Below is my try.
//DAL
//This is my interface
namespace iPublisher.DAL.Interfaces
{
public interface IReportHandler
{
IEnumerable<DocumentMapper> FetchDocuments(int clientId, int pager);
}
}
//my concrete class
public class ReportHandler : IReportHandler
{
public IEnumerable<DocumentMapper> FetchDocuments(int clientId, int pager)
{
//LINQ
}
}
//Factory Interface
namespace iPublisher.DAL.Interfaces
{
public interface IReportFactory
{
IReportHandler Create(int factoryId);
}
}
//Factory class
namespace iPublisher.DAL.Factory
{
public class ReportFactory : IReportFactory
{
private IReportHandler reportObj;
public IReportHandler Create(int factoryId)
{
switch (factoryId)
{
case 1:
reportObj = new ReportHandler();
return reportObj;
default:
throw new ArgumentException("");
}
}
}
}
//UI Layer
namespace iPublisher.Controllers
{
[Authorize]
[SessionExpire]
public class ReportsController : Controller
{
ReportFactory factObj = new ReportFactory();
public string GetAllDocuments(string url,int pager =0)
{
if (SessionInfo.IsAdmin)
{
var documentsDataJSON = GetDocumentIntoJson(SessionInfo.ClientID, pager);
return documentsDataJSON;
}
else
{
return "Sorry!! You are not authorized to perform this action";
}
}
private string GetDocumentIntoJson(int clientId, int pager)
{
IReportHandler reportObj = factObj.Create(1);
var documents = reportObj.FetchDocumentsList(clientId, pager);
string documentsDataJSON = JsonConvert.SerializeObject(documents);
return documentsDataJSON;
}
}
}
Code Metrics still showing Maintainability Index to 60.
What I am missing here or how can I improve my implementation?