Ejemplo n.º 1
0
 public int CreateHousehold(HouseHold aHousehold)
 {
     using (var scope = new TransactionScope()) {
         var dbEntity = new DataModel.Generated.HouseHold {
             HouseHoldLeaderMemberId = aHousehold.HouseHoldLeaderMemberId,
             Name      = aHousehold.Name,
             Area      = aHousehold.Area,
             StartDate = DateTime.Now.Date
         };
         _unitOfWork.HouseHoldRepository.Insert(dbEntity);
         _unitOfWork.Save();
         scope.Complete();
         return(dbEntity.HouseHoldId);
     }
 }
Ejemplo n.º 2
0
        public bool UpdateHousehold(HouseHold aHousehold)
        {
            var success = false;

            if (aHousehold != null)
            {
                using (var scope = new TransactionScope()) {
                    var hhDbModel = _unitOfWork.HouseHoldRepository.GetByID(aHousehold.HouseHoldId);
                    if (hhDbModel != null)
                    {
                        hhDbModel.Name = aHousehold.Name;
                        hhDbModel.Area = aHousehold.Area;
                        _unitOfWork.HouseHoldRepository.Update(hhDbModel);
                        _unitOfWork.Save();
                        scope.Complete();
                        success = true;
                    }
                }
            }
            return(success);
        }
Ejemplo n.º 3
0
 public bool UpdateHousehold(HouseHold aHousehold)
 {
     var success = false;
     if (aHousehold != null) {
         using (var scope = new TransactionScope()) {
             var hhDbModel = _unitOfWork.HouseHoldRepository.GetByID(aHousehold.HouseHoldId);
             if (hhDbModel != null) {
                 hhDbModel.Name = aHousehold.Name;
                 hhDbModel.Area = aHousehold.Area;
                 _unitOfWork.HouseHoldRepository.Update(hhDbModel);
                 _unitOfWork.Save();
                 scope.Complete();
                 success = true;
             }
         }
     }
     return success;
 }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
 public int CreateHousehold(HouseHold aHousehold)
 {
     using (var scope = new TransactionScope()) {
         var dbEntity = new DataModel.Generated.HouseHold {
             HouseHoldLeaderMemberId = aHousehold.HouseHoldLeaderMemberId,
             Name = aHousehold.Name,
             Area = aHousehold.Area,
             StartDate = DateTime.Now.Date
         };
         _unitOfWork.HouseHoldRepository.Insert(dbEntity);
         _unitOfWork.Save();
         scope.Complete();
         return dbEntity.HouseHoldId;
     }
 }