- mvcdemo.zip
- MvcDemo
- MvcDeme.Core
- MvcDemo.Common
- MvcDemo.Dal
- MvcDemo.sln
- MvcDemo.suo
- MvcDemo.Tests
- App.config
- bin
- Debug
- AutoMapper.dll
- log4net.dll
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Unity.dll
- Microsoft.Practices.Unity.pdb
- Microsoft.Practices.Unity.xml
- MvcDemo.Common.dll
- MvcDemo.Common.pdb
- MvcDemo.Core.dll
- MvcDemo.Core.pdb
- MvcDemo.Dal.dll
- MvcDemo.Dal.pdb
- MvcDemo.dll
- MvcDemo.pdb
- MvcDemo.Tests.dll
- MvcDemo.Tests.dll.config
- MvcDemo.Tests.pdb
- Controllers
- MvcDemo.Tests.csproj
- obj
- Debug
- Properties
- MvcDemo
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using MvcDemo.Core;
using MvcDemo.Core.Models;
using MvcDemo.Core.Interfaces;
using MvcDemo.Dal.EntityModels;
using MvcDemo.Dal;
using MvcDemo.Dal.Interfaces;
using System.Data;
namespace MvcDemo.Core
{
public class DocumentService : ServiceBase<IDocumentModel>, IDocumentService
{
public DocumentService()
: this(new DocumentRepository())
{
}
private IDocumentRepository _documentRepository;
public DocumentService(IDocumentRepository documentRepository)
{
_documentRepository = documentRepository ?? new DocumentRepository();
}
protected override Type LogPrefix
{
get { return this.GetType(); }
}
public DocumentListViewModel GetDocumentList(int PageSize, int CurrentPage)
{
try
{
if ((CurrentPage == 0) || (PageSize == 0))
return null;
IQueryable<Document> query = _documentRepository.GetQueryable();
DocumentListViewModel model = new DocumentListViewModel();
model.TotalItemCount = query.Count();
if (model.TotalItemCount == 0)
return null;
model.TotalPageCount = (int)Math.Ceiling((double)model.TotalItemCount / (double)PageSize);
if (model.TotalPageCount != 1)
query = query.OrderBy(x => x.DocumentName).Skip((CurrentPage - 1) * PageSize).Take(PageSize);
model.ThisPageItemCount = query.Count();
model.DocumentList = new List<DocumentViewModel>();
AutoMapper.Mapper.CreateMap<Document, DocumentViewModel>()
.ForMember(dest => dest.ID, opt => opt.MapFrom(src => src.DocumentId));
model.DocumentList = AutoMapper.Mapper.Map(query.ToList(), model.DocumentList);
return model;
}
catch (System.Exception e)
{
this.LogError("Error getting the document list", e);
return null;
}
}
public List<DocumentFileViewModel> GetDocumentFileList(int DocumentId)
{
try
{
if (DocumentId == 0)
return null;
IQueryable<Document> query = _documentRepository.GetQueryable();
FileVersion maxVersion = null;
AutoMapper.Mapper.CreateMap<DocFile, DocumentFileViewModel>()
.BeforeMap((s, d) => maxVersion = s.FileVersions.OrderBy(x => x.Version).FirstOrDefault())
.ForMember(dest => dest.ID, opt => opt.MapFrom(src => src.FileId))
.ForMember(dest => dest.VersionNumber, opt => opt.MapFrom(src => maxVersion.Version.ToString("V 0.0.0")))
.ForMember(dest => dest.AddedDate, opt => opt.MapFrom(src => maxVersion.AddedDate))
.ForMember(dest => dest.AddedBy, opt => opt.MapFrom(src => maxVersion.AddedByName))
.ForAllMembers(x => x.NullSubstitute("No Record Found"));
DocFile[] docFiles = query.SingleOrDefault(x => x.DocumentId == DocumentId).DocFiles.ToArray();
List<DocumentFileViewModel> dfList = new List<DocumentFileViewModel>();
dfList = AutoMapper.Mapper
.Map(docFiles, dfList);
return dfList;
}
catch (Exception e)
{
this.LogError("Error getting Document File List", e);
return null;
}
}
public DocumentViewModel GetSingle(Expression<Func<DocumentViewModel, bool>> whereCondition)
{
throw new NotImplementedException();
}
public void Add(DocumentViewModel entity)
{
throw new NotImplementedException();
}
public void Delete(DocumentViewModel entity)
{
throw new NotImplementedException();
}
public void Update(DocumentViewModel entity)
{
throw new NotImplementedException();
}
public IList<DocumentViewModel> GetAll(Expression<Func<DocumentViewModel, bool>> whereCondition)
{
throw new NotImplementedException();
}
public IList<DocumentViewModel> GetAll()
{
throw new NotImplementedException();
}
public IQueryable<DocumentViewModel> Query(Expression<Func<DocumentViewModel, bool>> whereCondition)
{
throw new NotImplementedException();
}
public long Count(Expression<Func<DocumentViewModel, bool>> whereCondition)
{
throw new NotImplementedException();
}
public long Count()
{
throw new NotImplementedException();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
In-depth coverage of Microsoft .Net, Cloud and many other cutting-edge Technologies.
-
The Mandelbrot set – someone has called it the thumb-print of God – is one of the most beautiful and remarkable discoveries in the entire history of mathematics. My profile picture is generated with that equation.
You may contact Nirosh for Consultations, Code Reviews and Architecture Guide Workshops via c_nir*o*sh@hotmail.com (Remove * to use)
View Nirosh L.W.C.'s profile on LinkedIn
Other Links