コード例 #1
0
        public HouseHoldDetailsViewModel GetHouseHoldViewModel(int houseHoldId)
        {
            //var dbEntity = _unitOfWork.HouseHoldRepository.GetByID(houseHoldId);
            //if (dbEntity != null && dbEntity.HouseHoldId > 0) {
            //    //AT: Custom mapping a field
            //    Mapper.CreateMap<DataModel.Generated.HouseHold, HouseHold>();
            //    var model = Mapper.Map<DataModel.Generated.HouseHold, HouseHold>(dbEntity);

            //    return model;
            //}
            //return null;
            var crit = new HouseHoldCriteria()
            {
                HouseHoldId = houseHoldId
            };
            var context    = _unitOfWork.DbContext;
            var houseHolds = (from hh in context.HouseHolds
                              join m in context.Members on hh.HouseHoldLeaderMemberId equals m.MemberId
                              where hh.HouseHoldId == crit.HouseHoldId
                              orderby hh.Name
                              select new HouseHold {
                HouseHoldId = hh.HouseHoldId,
                HouseHoldLeaderMemberId = hh.HouseHoldLeaderMemberId,
                Name = hh.Name,
                Area = hh.Area,
                State = hh.State,
                HouseHoldLeader = m.FirstName + " " + m.LastName
            }).FirstOrDefault();

            var hhMembers = (from hhm in context.HouseHoldMembers
                             join m in context.Members on hhm.MemberId equals m.MemberId
                             where (hhm.HouseHoldId == houseHoldId && hhm.EndDate == null)
                             orderby m.LastName, m.IsHeadOfFamily descending, m.DOB
                             select new Member {
                MemberId = m.MemberId,
                LastName = m.LastName,
                FirstName = m.FirstName,
                DateOfBirth = m.DOB.Value
            });                 //.ToPagedList(paging.CurrentPage, paging.ItemsPerPage);
            var vm = new HouseHoldDetailsViewModel()
            {
                HouseHoldId             = houseHolds.HouseHoldId,
                HouseHoldLeaderMemberId = houseHolds.HouseHoldLeaderMemberId,
                Name             = houseHolds.Name,
                Area             = houseHolds.Area,
                State            = houseHolds.State,
                HouseHoldLeader  = houseHolds.HouseHoldLeader,
                HouseHoldMembers = hhMembers.ToList()
            };

            return(vm);
        }
コード例 #2
0
        public IPagedList <HouseHold> GetHouseHolds(HouseHoldCriteria crit, PagingInfo paging)
        {
            using (var context = _unitOfWork.DbContext) {
                var houseHolds = (from hh in context.HouseHolds
                                  join m in context.Members on hh.HouseHoldLeaderMemberId equals m.MemberId
                                  where (!crit.HouseHoldId.HasValue || (hh.HouseHoldId == crit.HouseHoldId)) &&
                                  (string.IsNullOrEmpty(crit.Area) || (!string.IsNullOrEmpty(crit.Area) && hh.Area == crit.Area))
                                  orderby hh.Name
                                  select new HouseHold {
                    HouseHoldId = hh.HouseHoldId,
                    Name = hh.Name,
                    Area = hh.Area,
                    State = hh.State,
                    HouseHoldLeader = m.FirstName + " " + m.LastName
                });                  //.ToPagedList(paging.CurrentPage, paging.ItemsPerPage);

                var pagedList = houseHolds.ToPagedList(paging.CurrentPage, paging.ItemsPerPage);
                return(pagedList);
            }
        }
コード例 #3
0
        public HouseHoldDetailsViewModel GetHouseHoldViewModel(int houseHoldId)
        {
            //var dbEntity = _unitOfWork.HouseHoldRepository.GetByID(houseHoldId);
            //if (dbEntity != null && dbEntity.HouseHoldId > 0) {
            //    //AT: Custom mapping a field
            //    Mapper.CreateMap<DataModel.Generated.HouseHold, HouseHold>();
            //    var model = Mapper.Map<DataModel.Generated.HouseHold, HouseHold>(dbEntity);

            //    return model;
            //}
            //return null;
            var crit = new HouseHoldCriteria() { HouseHoldId = houseHoldId };
            var context = _unitOfWork.DbContext;
            var houseHolds = (from hh in context.HouseHolds
                              join m in context.Members on hh.HouseHoldLeaderMemberId equals m.MemberId
                              where hh.HouseHoldId == crit.HouseHoldId
                              orderby hh.Name
                              select new HouseHold {
                                  HouseHoldId = hh.HouseHoldId,
                                  HouseHoldLeaderMemberId = hh.HouseHoldLeaderMemberId,
                                  Name = hh.Name,
                                  Area = hh.Area,
                                  State = hh.State,
                                  HouseHoldLeader = m.FirstName + " " + m.LastName
                              }).FirstOrDefault();

            var hhMembers = (from hhm in context.HouseHoldMembers
                             join m in context.Members on hhm.MemberId equals m.MemberId
                             where (hhm.HouseHoldId == houseHoldId && hhm.EndDate == null)
                             orderby m.LastName, m.IsHeadOfFamily descending, m.DOB
                             select new Member {
                                 MemberId = m.MemberId,
                                 LastName = m.LastName,
                                 FirstName = m.FirstName,
                                 DateOfBirth = m.DOB.Value
                             });//.ToPagedList(paging.CurrentPage, paging.ItemsPerPage);
            var vm = new HouseHoldDetailsViewModel() {
                HouseHoldId = houseHolds.HouseHoldId,
                HouseHoldLeaderMemberId = houseHolds.HouseHoldLeaderMemberId,
                Name = houseHolds.Name,
                Area = houseHolds.Area,
                State = houseHolds.State,
                HouseHoldLeader = houseHolds.HouseHoldLeader,
                HouseHoldMembers = hhMembers.ToList()
            };

            return vm;
        }
コード例 #4
0
        public ActionResult List(string sortOrder, string currentFilter, string searchString, int? page)
        {
            ViewBag.CurrentSort = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "LastName" : "";
            ViewBag.DateSortParm = sortOrder == "MemberOf" ? "memberOf_desc" : "MemberOf";

            if (searchString != null) {
                page = 1;
            }
            else {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;
            var pageSize = 10;
            var pageNumber = (page ?? 1);
            int pageCount;

            var pagingInfo = new PagingInfo() { CurrentPage = 1, ItemsPerPage = 5 };
            var houseHoldCriteria = new HouseHoldCriteria();
            var houseHolds = _services.GetHouseHolds(houseHoldCriteria, pagingInfo);
            return View("List", houseHolds);
        }
コード例 #5
0
        public IPagedList<HouseHold> GetHouseHolds(HouseHoldCriteria crit, PagingInfo paging)
        {
            using (var context = _unitOfWork.DbContext) {
                var houseHolds = (from hh in context.HouseHolds
                                  join m in context.Members on hh.HouseHoldLeaderMemberId equals m.MemberId
                                  where (!crit.HouseHoldId.HasValue || (hh.HouseHoldId == crit.HouseHoldId))
                                        && (string.IsNullOrEmpty(crit.Area) || (!string.IsNullOrEmpty(crit.Area) && hh.Area == crit.Area))
                                  orderby hh.Name
                                  select new HouseHold {
                                      HouseHoldId = hh.HouseHoldId,
                                      Name = hh.Name,
                                      Area = hh.Area,
                                      State = hh.State,
                                      HouseHoldLeader = m.FirstName + " " + m.LastName
                                  });//.ToPagedList(paging.CurrentPage, paging.ItemsPerPage);

                var pagedList = houseHolds.ToPagedList(paging.CurrentPage, paging.ItemsPerPage);
                return pagedList;
            }
        }