79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using EnVisage.Models;
|
|
|
|
namespace EnVisage.Code.BLL
|
|
{
|
|
public class ContactManager : ManagerBase<Contact, ContactModel>
|
|
{
|
|
public ContactManager(EnVisageEntities dbContext)
|
|
: base(dbContext)
|
|
{
|
|
}
|
|
|
|
protected override Contact InitInstance()
|
|
{
|
|
return new Contact { Id = Guid.NewGuid() };
|
|
}
|
|
|
|
protected override Contact RetrieveReadOnlyById(Guid key)
|
|
{
|
|
return DataTable.AsNoTracking().FirstOrDefault(t => t.Id == key);
|
|
}
|
|
|
|
public override System.Data.Entity.DbSet<Contact> DataTable
|
|
{
|
|
get
|
|
{
|
|
return DbContext.Contacts;
|
|
}
|
|
}
|
|
|
|
public ContactModel LoadContactModel(Guid contactId)
|
|
{
|
|
if (contactId == Guid.Empty)
|
|
return null;
|
|
|
|
return ContactModelBasicQuery.FirstOrDefault(x => x.Id == contactId);
|
|
}
|
|
|
|
public List<ContactModel> GetContacts(Guid parentId)
|
|
{
|
|
if (parentId == Guid.Empty)
|
|
return null;
|
|
|
|
return ContactModelBasicQuery.Where(x => x.ParentId == parentId).ToList();
|
|
}
|
|
public ContactModel GetContactByName(string FirstName,string LastName, ContactType contactType)
|
|
{
|
|
return (ContactModel)ContactModelBasicQuery.FirstOrDefault(x => x.FirstName == FirstName && x.LastName == LastName && x.Type == contactType);
|
|
}
|
|
#region Private Members
|
|
|
|
private IQueryable<ContactModel> ContactModelBasicQuery
|
|
{
|
|
get
|
|
{
|
|
var query = DataTable.AsNoTracking()
|
|
.Select(x =>
|
|
new ContactModel()
|
|
{
|
|
Id = x.Id,
|
|
Type = (ContactType)x.Type,
|
|
FirstName = x.FirstName,
|
|
LastName = x.LastName,
|
|
Email = x.Email,
|
|
Phone = x.Phone,
|
|
ParentId = x.ParentId.HasValue ? x.ParentId.Value : Guid.Empty,
|
|
ProjectLinksCount = x.Contact2Project.Count,
|
|
ContactClassification = (InternalContactClassification)x.ContactClassification
|
|
});
|
|
|
|
return query;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |