Ejemplo n.º 1
0
        public object GetResult(ccEntities db, CC.Data.Services.IPermissionsBase permissionsBase)
        {
            var source = from c in db.Clients.Where(permissionsBase.ClientsFilter)
                         where c.Id == this.ClientId
                         from item in c.UnmetNeeds1
                         where item.ClientId == this.ClientId
                         select new
            {
                StartDate   = item.StartDate,
                WeeklyHours = item.WeeklyHours
            };

            var filtered = source;

            var ordered = filtered.OrderByField(this.sSortCol_0, this.sSortDir_0 == "asc");

            return(new jQueryDataTableResult
            {
                sEcho = this.sEcho,
                iTotalDisplayRecords = filtered.Count(),
                iTotalRecords = source.Count(),
                aaData = ordered.Skip(this.iDisplayStart).Take(this.iDisplayLength).ToList().Select(f => new
                {
                    StartDate = f.StartDate.ToShortDateString(),
                    IsoStartDate = f.StartDate.ToString("s"),
                    WeeklyHours = f.WeeklyHours.ToString()
                })
            });
        }
        public override void Load(ccEntities db, IPermissionsBase permissions, int id)
        {
            base.Load(db, permissions, id);

            this.Comments = db.Comments.Where(f => f.MainReportInternalComments.Any(m => m.Id == id)).OrderByDescending(f => f.Date)
                            .Select(f => new CommentViewModel()
            {
                Content  = f.Content,
                UserName = f.User.UserName,
                Date     = f.Date
            }).OrderByDescending(f => f.Date).ToList();

            switch ((FixedRoles)this.User.RoleId)
            {
            case FixedRoles.Admin:
            case FixedRoles.RegionOfficer:
            case FixedRoles.GlobalOfficer:
                this.CanAddRemarks = true;
                break;

            default:
                this.CanAddRemarks = false;
                break;
            }
        }
Ejemplo n.º 3
0
        private static void InsertClient(ccEntities db, Client client)
        {
            var clientproperties = typeof(Client).GetProperties();
            var method           = typeof(ccEntities).GetMethod("Insert");
            var parameters       = method.GetParameters();
            var values           = new List <object>();
            var q = from p in parameters
                    join prop in clientproperties on p.Name.ToLowerInvariant() equals prop.Name.ToLowerInvariant() into g
                    from prop in g.DefaultIfEmpty()
                    select prop == null ? null : prop.GetValue(client);

            //db.Insert(client.Id, client.MasterId, client.AgencyId, client.NationalId, client.NationalIdTypeId,
            //	client.FirstName, client.MiddleName, client.LastName, client.Phone, client.BirthDate, client.Address, client.City, client.StateId,
            //	client.ZIP, client.JoinDate, client.LeaveDate, client.LeaveReasonId, client.LeaveRemarks, client.DeceasedDate, client.ApprovalStatusId, client.FundStatusId, client.IncomeCriteriaComplied,
            //	client.IncomeVerificationRequired, client.NaziPersecutionDetails, client.Remarks, client.PobCity, client.PobCountry,
            //	client.EmigrationDate, client.PrevFirstName, client.PrevLastName, client.OtherFirstName, client.OtherLastName,
            //	client.OtherDob, client.OtherId, client.OtherIdTypeId, client.OtherAddress, client.PreviousAddressInIsrael,
            //	client.CompensationProgramName, client.IsCeefRecipient, client.CeefId, client.AddCompName, client.AddCompId, client.GfHours,
            //	client.GovHcHours, client.ExceptionalHours, client.UpdatedById, client.UpdatedAt, client.CreatedAt, client.SS_,
            //	client.A2, client.HARDSHIP, client.CEEF, client.CEEF, client.MatchFlag, client.UserNameMatch, client.DateMatch,
            //	client.Date_of_birth_was_not_matched, client.Provided_other_DOB, client.Identification_Card___was_not_matched,
            //	client.Provided_other_ID_Card, client.Other_addresses_required, client.Provided_other_addresses,
            //	client.Previous_address_in_Israel_required, client.Provided_previous_address_in_Israel, client.New_Client);

            var retval = method.Invoke(db, q.ToArray());
        }
        public CcRepository()
        {
            _dataContext = new ccEntities();
            _dataContext.SavingChanges += new EventHandler(_dataContext_SavingChanges);

            CreateRepositories(_dataContext);
        }
Ejemplo n.º 5
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            using (ccEntities context = new ccEntities())
            {
                var membershipUser = context.MembershipUsers
                                     .Include(f => f.User)
                                     .SingleOrDefault(f => f.LoweredUserName == filterContext.HttpContext.User.Identity.Name);

                if (membershipUser != null)
                {
                    if (PasswordExpiresInDays > 0 && (membershipUser.LastPasswordChangedDate == null || ((DateTime)membershipUser.LastPasswordChangedDate).AddDays(PasswordExpiresInDays) < DateTime.Now.Date) || membershipUser.User.TemporaryPassword)
                    {
                        if (!filterContext.HttpContext.Request.IsJsonRequest())
                        {
                            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Account", action = "ChangePassword" }));
                        }
                        else
                        {
                            filterContext.Result = new jsdtr()
                            {
                                Data = new {
                                    errorCode = "PasswordExpired",
                                    message   = "Password has expired"
                                }, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                            };
                            filterContext.HttpContext.Response.StatusCode             = 403;
                            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
                        }
                    }
                }
            }
            base.OnAuthorization(filterContext);
        }
 public FundStatusConverter()
 {
     using (var db = new ccEntities())
     {
         _fundStatuses = db.FundStatuses.ToList();
     }
 }
        public void CreatePost_Test()
        {
            ClientCreateModel cm = new ClientCreateModel();

            cm.Data = new Client();
            string randomName = System.IO.Path.GetRandomFileName();

            cm.Data.FirstName = randomName;
            cm.Data.LastName  = "last";
            cm.Data.City      = "city";
            cm.Data.Address   = "address";
            cm.Data.AgencyId  = new ccEntities().Agencies.First().Id;
            cm.Data.CountryId = new ccEntities().Countries.First().Id;
            cm.Data.JoinDate  = DateTime.Now;


            ActionResult actual = Target.Create(cm);



            ccEntities context   = new ccEntities();
            Client     newClient = context.Clients.Single(x => x.FirstName == randomName);

            Assert.IsNotNull(newClient == null, "new client was not created");

            Assert.IsTrue(newClient.City == "city", "new client city was not saved");
        }
Ejemplo n.º 8
0
        public JsonResult PreviewData(Guid id, CC.Web.Models.jQueryDataTableParamModel jq)
        {
            CheckImportIdPermissions(id);

            using (var db = new ccEntities())
            {
                var HomeCareEntitledPeriods = db.HomeCareEntitledPeriods;
                var ImportHceps             = db.ImportHceps;
                var q        = PreviewDataQuery(id, db, HomeCareEntitledPeriods, ImportHceps);
                var filtered = q;
                var sorted   = filtered.OrderByDescending(f => f.Errors.Count());
                if (jq.iSortCol_0 != 1)
                {
                    sorted = filtered.OrderByField(Request["mDataProp_" + jq.iSortCol_0], jq.sSortDir_0 == "asc");
                }
                if (Request["iSortCol_1"] != null && jq.iSortCol_0 != 1)
                {
                    sorted = sorted.ThenByField(Request["mDataProp_" + Request["iSortCol_1"]], Request["sSortDir_1"] == "asc");
                }
                if (Request["iSortCol_2"] != null && jq.iSortCol_0 != 1)
                {
                    sorted = sorted.ThenByField(Request["mDataProp_" + Request["iSortCol_2"]], Request["sSortDir_2"] == "asc");
                }

                var result = new jQueryDataTableResult()
                {
                    sEcho = jq.sEcho,
                    iTotalDisplayRecords = filtered.Count(),
                    iTotalRecords        = q.Count(),
                    aaData = sorted.Skip(jq.iDisplayStart).Take(jq.iDisplayLength).ToList()
                };
                return(this.MyJsonResult(result, JsonRequestBehavior.AllowGet));
            }
        }
 public Repository(ccEntities objectContext)
 {
     _objectContext = objectContext as ccEntities;
     _objectSet     = objectContext.CreateObjectSet <T>();
     _objectContext.SavingChanges      += new EventHandler(_objectContext_SavingChanges);
     _objectContext.ObjectMaterialized += new ObjectMaterializedEventHandler(_objectContext_ObjectMaterialized);
 }
Ejemplo n.º 10
0
        public static void CreateClient(string FirstName, string LastName, string AgencyName)
        {
            var    context    = new ccEntities();
            Client c1         = new Client();
            int    UpdateById = context.Users.First().Id;


            c1.Agency = context.Agencies.First(c => c.Name == AgencyName);


            c1.FirstName   = FirstName;
            c1.LastName    = LastName;
            c1.UpdatedById = UpdateById;
            c1.CountryId   = c1.Agency.AgencyGroup.CountryId;
            c1.StateId     = c1.Agency.AgencyGroup.StateId;
            c1.JoinDate    = DateTime.Now;

            try
            {
                var client = context.Clients.First(x => x.FirstName == FirstName);
            }
            catch
            {
                context.Clients.AddObject(c1);
                context.SaveChanges();
            }
        }
Ejemplo n.º 11
0
        public object GetPreview(ccEntities db, CC.Web.Models.jQueryDataTableParamModel jq)
        {
            var q = PreviewData(db);


            var filtered = q;

            if (!string.IsNullOrEmpty(jq.sSearch))
            {
                filtered = filtered.Where(f => f.FundName.Contains(jq.sSearch) ||
                                          f.AgencyGroupName.Contains(jq.sSearch) ||
                                          f.Name.Contains(jq.sSearch) ||
                                          f.CurrencyId.Equals(jq.sSearch));
            }

            var ordered = filtered.OrderByField(jq.sSortCol_0, jq.bSortDir_0);

            return(new CC.Web.Models.jQueryDataTableResult <object>
            {
                aaData = ordered.Skip(jq.iDisplayStart).Take(jq.iDisplayLength).ToList(),
                iTotalDisplayRecords = filtered.Count(),
                iTotalRecords = q.Count(),
                sEcho = jq.sEcho
            });
        }
        public object GetResult(ccEntities db, CC.Data.Services.IPermissionsBase permissionsBase)
        {
            var source = from c in db.Clients.Where(permissionsBase.ClientsFilter)
                         where c.Id == this.ClientId
                         from item in c.GrandfatherHours
                         where item.ClientId == this.ClientId
                         select new
            {
                StartDate = item.StartDate,
                Value     = item.Value,
                Type      = item.Type
            };

            var filtered = source;

            var ordered = filtered.OrderByField(this.sSortCol_0, this.sSortDir_0 == "asc");

            return(new jQueryDataTableResult
            {
                sEcho = this.sEcho,
                iTotalDisplayRecords = filtered.Count(),
                iTotalRecords = source.Count(),
                aaData = ordered.Skip(this.iDisplayStart).Take(this.iDisplayLength).ToList().Select(f => new
                {
                    StartDate = f.StartDate.ToShortDateString(),
                    IsoStartDate = f.StartDate.ToString("s"),
                    Value = f.Value.ToString(),
                    Type = f.Type == 0 ? "Grandfathered" : f.Type == 1 ? "Exceptional" : "BMF Approved"
                           //Type = f.Type == 0 ? "Grandfathered" : "Exceptional"
                })
            });
        }
Ejemplo n.º 13
0
 public virtual Dictionary <int, string> GetAllowedServiceTypes()
 {
     using (var db = new ccEntities())
     {
         return(db.ServiceTypes.Where(f => !f.DoNotReportInUnmetNeedsOther).Select(f => new { Id = f.ServiceTypeImportId ?? f.Id, Name = f.Name }).ToDictionary(f => f.Id, f => f.Name));
     }
 }
        public object GetResult(ccEntities db, CC.Data.Services.IPermissionsBase permissionsBase)
        {
            var source = from c in db.Clients.Where(permissionsBase.ClientsFilter)
                         where c.Id == this.ClientId
                         from item in c.UnmetNeedsOthers
                         where item.ClientId == this.ClientId
                         select new
            {
                ServiceTypeID = item.ServiceTypeId,
                ServiceType   = item.ServiceType.Name,
                Amount        = item.Amount,
                CUR           = item.CurrencyId
            };

            var filtered = source;

            var ordered = filtered.OrderByField(this.sSortCol_0, this.sSortDir_0 == "asc");

            return(new jQueryDataTableResult
            {
                sEcho = this.sEcho,
                iTotalDisplayRecords = filtered.Count(),
                iTotalRecords = source.Count(),
                aaData = ordered.Skip(this.iDisplayStart).Take(this.iDisplayLength).ToList().Select(f => new
                {
                    ServiceTypeId = f.ServiceTypeID,
                    ServiceType = f.ServiceType,
                    Amount = f.Amount.Format(),
                    CUR = f.CUR
                })
            });
        }
Ejemplo n.º 15
0
        public static void CreateAgency(string agencyName, string groupName)
        {
            var context = new ccEntities();


            int gr_id = 0;


            var gr = context.AgencyGroups.Where(x => x.Name == groupName);

            if (gr.Any())
            {
                gr_id = gr.First().Id;
            }


            var ag = context.Agencies.Where(x => x.Name == agencyName);

            if (!ag.Any())
            {
                Agency a = new Agency();
                a.Name    = agencyName;
                a.GroupId = gr_id;
                context.Agencies.AddObject(a);
                try
                {
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }
        }
Ejemplo n.º 16
0
        public static User GetUser(FixedRoles role, string AgencyName = "")
        {
            var    context = new ccEntities();
            User   newUser;
            string userName = "******" + role.ToString();

            try
            {
                newUser = context.Users.First(c => c.UserName == userName);
            }
            catch
            {
                newUser = User.CreateUser(userName, userName);
                if (AgencyName == "")
                {
                    AgencyName = "Agency1_FirstTest";
                }
                Agency a1 = context.Agencies.First(c => c.Name == AgencyName);
                newUser.AgencyId = a1.Id;
                newUser.RoleId   = (int)role;
                newUser.Email    = userName;
                //   newUser.RegionId = a1.RegionId;
                newUser.AgencyGroupId = a1.AgencyGroup.Id;
                newUser.MembershipUser.SetPassword(userName);
                context.Users.AddObject(newUser);
                context.MembershipUsers.AddObject(newUser.MembershipUser);

                context.SaveChanges();
            }

            return(newUser);
        }
        public object GetData()
        {
            using (var db = new ccEntities())
            {
                var source = PreviewQuery(db, Permissions, Id);

                var filtered = source;
                IOrderedQueryable <DataRow> ordered = null;
                if (this.sSortCol_0 == "RowErrors")
                {
                    ordered = source.OrderBy(f => f.RowErrors.Any, this.sSortDir_0 == "asc");
                }
                else
                {
                    ordered = source.OrderByField(this.sSortCol_0, this.sSortDir_0 == "asc");
                }

                return(new jQueryDataTableResult
                {
                    aaData = ordered.Skip(this.iDisplayStart).Take(this.iDisplayLength).ToList(),
                    iTotalDisplayRecords = filtered.Count(),
                    iTotalRecords = source.Count(),
                    sEcho = sEcho
                });
            }
        }
        public override jQueryDataTableResult GetResult(ccEntities db, IPermissionsBase permissions)
        {
            var source =
                from c in db.Clients.Where(permissions.ClientsFilter)
                where c.Id == this.ClientId
                join cr in db.ViewClientReports on c.Id equals cr.ClientId

                join sr in db.SubReports.Where(permissions.SubReportsFilter) on cr.SubReportId equals sr.Id
                where sr.AppBudgetService.Service.TypeId != (int)Service.ServiceTypes.EmergencyAssistance
                where sr.AppBudgetService.Service.ReportingMethodId != (int)Service.ReportingMethods.Homecare &&
                sr.AppBudgetService.Service.ReportingMethodId != (int)Service.ReportingMethods.HomecareWeekly
                let clientReportsCount = sr.ClientReports.Count()
                                         select new ostr
            {
                MrStart         = sr.MainReport.Start,
                MrEnd           = (DateTime)System.Data.Objects.EntityFunctions.AddDays(sr.MainReport.End, -1),
                Quantity        = cr.Quantity,
                Amount          = cr.TotalAmount,
                EstAmount       = clientReportsCount == 0 ? (decimal?)null : sr.Amount / clientReportsCount,
                Cur             = sr.AppBudgetService.AppBudget.App.CurrencyId,
                ServiceId       = sr.AppBudgetService.ServiceId,
                ServiceName     = sr.AppBudgetService.Service.Name,
                ServiceTypeName = sr.AppBudgetService.Service.ServiceType.Name,
                AppName         = sr.AppBudgetService.AppBudget.App.Name,
                FundName        = sr.AppBudgetService.AppBudget.App.Fund.Name,
                MasterFundName  = sr.AppBudgetService.AppBudget.App.Fund.MasterFund.Name,
                SubReportId     = sr.Id,
                MasterFundId    = sr.AppBudgetService.AppBudget.App.Fund.MasterFundId
            };
            var filtered = source;

            if (StartDate.HasValue)
            {
                filtered = filtered.Where(f => f.Date >= this.StartDate);
            }
            if (EndDate.HasValue)
            {
                filtered = filtered.Where(f => f.Date <= this.EndDate);
            }
            if (this.ServiceId.HasValue)
            {
                filtered = filtered.Where(f => f.ServiceId == this.ServiceId);
            }
            if (this.sSortCol_0 == "DateName")
            {
                this.sSortCol_0 = "Date";
            }
            var sorted = filtered.OrderByField(this.sSortCol_0, this.sSortDir_0 == "asc");

            var data = sorted.Skip(this.iDisplayStart).Take(this.iDisplayLength).ToList();

            return(new jQueryDataTableResult
            {
                sEcho = this.sEcho,
                aaData = data,
                iTotalRecords = source.Count(),
                iTotalDisplayRecords = filtered.Count()
            });
        }
Ejemplo n.º 19
0
        public IRepository <Agency> GetAgenciesByRole(FixedRoles role, string AgencyName = "")
        {
            User         user   = Helper.GetUser(role, AgencyName);
            ccEntities   entity = new ccEntities(user);
            CcRepository cr     = new CcRepository(user);

            return(cr.Agencies);
        }
Ejemplo n.º 20
0
        public void GetAgenciesForAdmin()
        {
            IRepository <Agency> ag1 = GetAgenciesByRole(FixedRoles.GlobalOfficer);

            IQueryable <Agency> ag2 = new ccEntities().Agencies;

            Assert.IsTrue(ag1.Select.Count() == ag2.Count(), "Admin can see all agencies");
        }
 HelpTableConverter()
 {
     using (var db = new ccEntities())
     {
         var objectset = db.CreateObjectSet <T>();
         this.list = objectset.ToList();
     }
 }
Ejemplo n.º 22
0
        public void UpdateClientsCount(ccEntities db)
        {
            var newClients = db.Clients.Where(f => f.ApprovalStatusId == (int)ApprovalStatusEnum.New)
                             .Where(f => !AgencyGroup.TestIds.Contains(f.Agency.GroupId));

            NewClientsCount         = newClients.Count();
            NewClientsExportedCount = newClients.Where(f => f.ACPExported).Count();
        }
 public static IPermissionsBase GetPermissionsFor(string username)
 {
     using (var db = new ccEntities())
     {
         var user = db.Users.Single(f => f.UserName == username);
         return(GetPermissionsFor(user));
     }
 }
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        ///

        public ClientsController GetTarget_ForUser(FixedRoles role, string AgencyName = "")
        {
            ClientsController target  = new ClientsController();
            ccEntities        context = new ccEntities();

            target.CcUser = Helper.GetUser(role, AgencyName);
            return(target);
        }
Ejemplo n.º 25
0
        public static List <FunctionalityChangeRow> FunctionalityChangeReportHelper(ccEntities db, CC.Data.Services.IPermissionsBase Permissions, int?regionId, int?countryId, int?agencyGroupId)
        {
            var date30DaysAgo  = DateTime.Now.AddDays(-30);
            var date180DaysAgo = DateTime.Now.AddDays(-180);

            var q = from a in db.viewFunctionalityScoreChangeReports
                    where regionId == null || a.RegionId == regionId
                    where countryId == null || a.CountryId == countryId
                    where agencyGroupId == null || a.AgencyGroupId == agencyGroupId
                    where a.UpdatedAt >= date30DaysAgo ? a.UpdatedAt >= date180DaysAgo : false
                    join c in db.Clients.Where(Permissions.ClientsFilter) on a.ClientId equals c.Id
                    select new
            {
                ClientId        = a.ClientId,
                RegionId        = a.RegionId,
                CountryId       = a.CountryId,
                AgencyGroupId   = a.AgencyGroupId,
                AgencyName      = a.AgencyName,
                DiagnosticScore = a.DiagnosticScore,
                StartDate       = a.StartDate
            };

            var q1 = q.OrderBy(f => f.ClientId).ThenByDescending(f => f.StartDate).GroupBy(f => f.ClientId).ToList();

            List <FunctionalityChangeRow> functionalityChangeList = new List <FunctionalityChangeRow>();

            foreach (var item in q1)
            {
                FunctionalityChangeRow fcr = new FunctionalityChangeRow();
                for (int i = 0; i < item.Count(); i++)
                {
                    switch (i)
                    {
                    case 0: fcr.ActiveScore   = item.ElementAt(i).DiagnosticScore;
                        fcr.DateOfActiveScore = item.ElementAt(i).StartDate;
                        break;

                    case 1: fcr.PriorScore   = item.ElementAt(i).DiagnosticScore;
                        fcr.DateOfPriorScore = item.ElementAt(i).StartDate;
                        break;

                    case 2: fcr.PriorPriorScore   = item.ElementAt(i).DiagnosticScore;
                        fcr.DateOfPriorPriorScore = item.ElementAt(i).StartDate;
                        break;

                    default:
                        break;
                    }
                }
                var temp = item.First();
                fcr.ClientId   = temp.ClientId;
                fcr.AgencyName = temp.AgencyName;
                functionalityChangeList.Add(fcr);
            }

            return(functionalityChangeList.OrderBy(f => f.DateOfActiveScore).ToList());
        }
Ejemplo n.º 26
0
        public ActionResult Import(Guid id)
        {
            using (var db = new ccEntities())
            {
                var res = db.ImportHcepProc(id, Permissions.User.AgencyId, Permissions.User.AgencyGroupId, Permissions.User.RegionId);

                return(RedirectToAction("Index", "Clients"));
            }
        }
Ejemplo n.º 27
0
        public ClientsIndexModel()
        {
            HistoryExportModel = new HistoryExportModel();

            using (var db = new ccEntities())
            {
                UpdateClientsCount(db);
            }
        }
 public FundStatusTypeConverter()
 {
     using (var db = new ccEntities())
     {
         db.ContextOptions.LazyLoadingEnabled   = false;
         db.ContextOptions.ProxyCreationEnabled = false;
         fundstatuses = db.FundStatuses.ToList();
     }
 }
        public override jQueryDataTableResult GetResult(ccEntities db, IPermissionsBase permissions)
        {
            var source = from cr in db.EmergencyReports.Where(permissions.EmergencyReportsFilter)
                         .Where(f => GGOnly ? f.SubReport.AppBudgetService.AppBudget.App.Fund.MasterFundId == 73 : true)
                         where cr.ClientId == this.ClientId
                         where cr.SubReport.AppBudgetService.Service.TypeId == (int)Service.ServiceTypes.EmergencyAssistance
                         select new etr
            {
                Date           = cr.ReportDate,
                Amount         = cr.Amount,
                Discretionary  = cr.Discretionary,
                Total          = cr.Total,
                TypeId         = cr.TypeId,
                TypeName       = cr.EmergencyReportType.Name,
                PurposeOfGrant = cr.Remarks,
                Cur            = cr.SubReport.AppBudgetService.AppBudget.App.CurrencyId,
                ServiceId      = cr.SubReport.AppBudgetService.ServiceId,
                ServiceName    = cr.SubReport.AppBudgetService.Service.Name,
                AppName        = cr.SubReport.AppBudgetService.AppBudget.App.Name,
                FundName       = cr.SubReport.AppBudgetService.AppBudget.App.Fund.Name,
                MasterFundName = cr.SubReport.AppBudgetService.AppBudget.App.Fund.MasterFund.Name,
                SubReportId    = cr.SubReport.Id
            };
            var filtered = source;

            if (StartDate.HasValue)
            {
                filtered = filtered.Where(f => f.Date >= this.StartDate);
            }
            if (EndDate.HasValue)
            {
                filtered = filtered.Where(f => f.Date <= this.EndDate);
            }
            if (this.ServiceId.HasValue)
            {
                filtered = filtered.Where(f => f.ServiceId == this.ServiceId);
            }
            if (this.TypeId.HasValue)
            {
                filtered = filtered.Where(f => f.TypeId == this.TypeId);
            }
            if (this.sSortCol_0 == "DateName")
            {
                this.sSortCol_0 = "Date";
            }
            var sorted = filtered.OrderByField(this.sSortCol_0, this.sSortDir_0 == "asc");

            var data = sorted.Skip(this.iDisplayStart).Take(this.iDisplayLength).ToList();

            return(new jQueryDataTableResult
            {
                sEcho = this.sEcho,
                aaData = data,
                iTotalRecords = source.Count(),
                iTotalDisplayRecords = filtered.Count()
            });
        }
        protected override void Dispose(bool disposing)
        {
            if (db != null)
            {
                db.Dispose();
                db = null;
            }

            base.Dispose(disposing);
        }