예제 #1
0
 public ActionResult Create()
 {
     ViewBag.Title = "New HouseHold";
     var vm = new HouseHoldDetailsViewModel() {Name = "NAME OF HOUSEHOLD"};
     var list = _services.GetHeadOfFamilyMembers();
     //var list = _services.GetHeadOfFamilyMembers(houseHoldId, houseHoldLeaderMemberId).ToList();
     vm.HeadOfFamilyMembersList = new SelectList(list, "MemberId", "FullName");
     return View("EditHousehold", vm);
 }
예제 #2
0
        public ActionResult EditHousehold(HouseHoldDetailsViewModel houseHoldViewModel)
        {
            if (ModelState.IsValid) {
                var aHousehold = new HouseHold()
                {
                    HouseHoldId = houseHoldViewModel.HouseHoldId,
                    HouseHoldLeaderMemberId = houseHoldViewModel.HouseHoldLeaderMemberId,
                    Name = houseHoldViewModel.Name,
                    Area = houseHoldViewModel.Area
                };

                if (houseHoldViewModel.HouseHoldId > 0) {
                    _services.UpdateHousehold(aHousehold);
                }
                else {
                   var newHhId = _services.CreateHousehold(aHousehold);
                    houseHoldViewModel.HouseHoldId = newHhId;
                }

                TempData["message"] = string.Format("{0} has been saved", aHousehold.Name);
                //ModelState.Clear();
                return RedirectToAction("EditHousehold", new { houseHoldId= houseHoldViewModel.HouseHoldId});
                //return View(houseHoldViewModel);
                //return View("EditHousehold", houseHoldViewModel);
            }
            else {
                // there is something wrong with the data values
                return View("EditHousehold", houseHoldViewModel);
            }
        }
예제 #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;
        }