/BugTracker/BugTracker.BusinessLogic/BTUser/ReportedBy/ReportedByService.cs
C# | 248 lines | 224 code | 24 blank | 0 comment | 69 complexity | 54512e3722eb185ed49c01541df1f3b9 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Dynamic;
- using System.Data.Entity;
- using BugTracker.DataAccess.Data;
-
- namespace BugTracker.BusinessLogic.ReportedBy
- {
- public class ReportedByService : IReportedByService
- {
- private BugTrackerEntities db = null;
- private IReportedByMapper mapper = null;
-
- public ReportedByService(BugTrackerEntities db, ReportedByMapper mapper)
- {
- if (db == null)
- throw new ArgumentNullException("db");
- if (mapper == null)
- throw new ArgumentNullException("mapper");
- this.db = db;
- this.mapper = mapper;
- }
-
- #region IDataService<ReportedBy> Members
-
- public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> Load()
- {
- IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
- var results = (from models in db.ReportedBies
- where models.IsActive == true &
- models.IsDeleted == false select models);
- if(results != null)
- {
- collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
- foreach(var item in results)
- collection.Add(mapper.Map(item));
-
- }
- return collection;
- }
-
- public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> LoadIncludeInactive()
- {
- IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
- var results = (from models in db.ReportedBies
- where models.IsDeleted == false select models);
- if(results != null)
- {
- collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
- foreach(var item in results)
- collection.Add(mapper.Map(item));
-
- }
- return collection;
- }
-
- public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> Page(int pageIndex, int pageSize, out int count)
- {
- IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
- count = this.Count();
- var results = (from models in db.ReportedBies
- where models.IsActive == true & models.IsDeleted == false
- select models).Skip(pageIndex * pageSize).Take(pageSize);
- if (results != null)
- {
- collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
- foreach (var item in results)
- collection.Add(mapper.Map(item));
- }
- return collection;
- }
-
- public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> PageSort(int pageIndex, int pageSize, string sortColumn, string sortDirection, out int count)
- {
- IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
- count = this.Count();
- var results = (from models in db.ReportedBies
- where models.IsActive == true & models.IsDeleted == false
- select models)
- .OrderBy("it." + sortColumn + " " + sortDirection)
- .Skip(pageIndex * pageSize)
- .Take(pageSize);
- if (results != null)
- {
- collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
- foreach (var item in results)
- collection.Add(mapper.Map(item));
- }
- return collection;
- }
-
- public IList<BusinessEntities.Entities.ReportedBy.ReportedBy> PageSortWhere(int pageIndex, int pageSize, string sortColumn, string sortDirection, string whereColumn, string whereClause, out int count)
- {
- IList<BusinessEntities.Entities.ReportedBy.ReportedBy> collection = null;
- count = this.Count();
- var results = (from models in db.ReportedBies
- where models.IsActive == true & models.IsDeleted == false
- select models)
- .Where("it." + whereColumn + " " + whereClause)
- .OrderBy("it." + sortColumn + " " + sortDirection)
- .Skip(pageIndex * pageSize)
- .Take(pageSize);
- if (results != null)
- {
- collection = new List<BusinessEntities.Entities.ReportedBy.ReportedBy>();
- foreach (var item in results)
- collection.Add(mapper.Map(item));
- }
- return collection;
- }
-
- public BusinessEntities.Entities.ReportedBy.ReportedBy LoadById(int id)
- {
- var results = (from models in db.ReportedBies
- where models.ReportedByID == id & models.IsActive == true & models.IsDeleted == false
- select models).FirstOrDefault();
- return mapper.Map(results);
- }
-
- public BusinessEntities.Entities.ReportedBy.ReportedBy LoadByGuid(Guid guid)
- {
- var results = (from models in db.ReportedBies
- where models.RowGuid == guid & models.IsActive == true & models.IsDeleted == false
- select models).FirstOrDefault();
- return mapper.Map(results);
- }
-
- public int Count()
- {
- return (from models in db.ReportedBies
- where models.IsActive == true &
- models.IsDeleted == false select models).Count();
- }
-
- public int CountIncludeInactive()
- {
- return (from models in db.ReportedBies
- where models.IsDeleted == false
- select models).Count();
- }
-
- public bool HasChanged(int id)
- {
- return ((from models in db.ReportedBies
- where models.ReportedByID == id & models.IsActive == true & models.IsDeleted == false
- select models.ModifiedOn).Cast<DateTime>().First() > DateTime.Now);
- }
-
- public bool HasChanged(Guid guid)
- {
- return ((from models in db.ReportedBies
- where models.RowGuid == guid & models.IsActive == true & models.IsDeleted == false
- select models.ModifiedOn).Cast<DateTime>().First() > DateTime.Now);
- }
-
- public void MakeInactive(BusinessEntities.Entities.ReportedBy.ReportedBy value)
- {
- var results = (from models in db.ReportedBies
- where models.ReportedByID == value.ReportedByID &
- models.IsActive == true &
- models.IsDeleted == false
- select models).First();
- if(results != null)
- {
- results.IsActive = false;
- db.SaveChanges();
- }
- }
-
- public void InsertObject(BusinessEntities.Entities.ReportedBy.ReportedBy value)
- {
- db.ReportedBies .AddObject(mapper.Map(value));
- db.SaveChanges();
- }
-
- public void UpdateObject(BusinessEntities.Entities.ReportedBy.ReportedBy value)
- {
- var model = (from models in db.ReportedBies
- where models.ReportedByID == value.ReportedByID &
- models.IsActive == true &
- models.IsDeleted == false
- select models).First();
- if (model != null)
- {
- mapper.Map(model, value);
- db.SaveChanges();
- }
- }
-
- public void DeleteObject(BusinessEntities.Entities.ReportedBy.ReportedBy value)
- {
- var results = (from models in db.ReportedBies
- where models.ReportedByID == value.ReportedByID &
- models.IsActive == true &
- models.IsDeleted == false
- select models).First();
- if (results != null)
- {
- results.IsDeleted = true;
- db.SaveChanges();
- }
- }
-
- public void DeleteObject(int id)
- {
- var results = (from models in db.ReportedBies
- where models.ReportedByID == id &
- models.IsActive == true &
- models.IsDeleted == false
- select models).First();
- if (results != null)
- {
- results.IsDeleted = true;
- db.SaveChanges();
- }
- }
-
- public void DeleteObject(Guid guid)
- {
- var results = (from models in db.ReportedBies
- where models.RowGuid == guid &
- models.IsActive == true &
- models.IsDeleted == false
- select models).First();
- if (results != null)
- {
- results.IsDeleted = true;
- db.SaveChanges();
- }
- }
-
- public bool HasDuplicate(BusinessEntities.Entities.ReportedBy.ReportedBy value)
- {
- var results = (from models in db.ReportedBies
- where models.FirstName == value.FirstName &
- models.LastName == value.LastName &
- models.Email == value.Email &
- models.IsActive == true &
- models.IsDeleted == false
- select models).First();
- return (results == null) ? false : true;
- }
-
- #endregion
- }
- }