public void UpdateMember(Member aMember) { var gender = string.IsNullOrEmpty(aMember.Gender) ? (char?)null : aMember.Gender[0]; using (var scope = new TransactionScope()) { var dbMember = _unitOfWork.MemberRepository.GetByID(aMember.MemberId); dbMember.MemberId = aMember.MemberId; dbMember.FirstName = aMember.FirstName; dbMember.LastName = aMember.LastName; dbMember.DOB = aMember.DateOfBirth; dbMember.Gender = gender.ToString(); dbMember.Phone = aMember.Phone; dbMember.Email = aMember.Email; //SpouseMemberId = aMember.SpouseMemberId, dbMember.IsHeadOfFamily = aMember.IsHeadOfFamily; //string.IsNullOrEmpty(MyString) ? (char?)null : MyString[0] //AT: We need to do manual mapping above. We can use code below but need to add the Ignore fields that we don't want updated // Mapper.CreateMap<Member, DataModel.Generated.Member > () //.ForMember(dest => dest.DOB, // opts => opts.MapFrom(src => src.DateOfBirth)); // var dbMember = Mapper.Map<Member, DataModel.Generated.Member>(aMember); _unitOfWork.MemberRepository.Update(dbMember); _unitOfWork.Save(); scope.Complete(); } }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { Member memberContext = (controllerContext.HttpContext.Session != null) ? (controllerContext.HttpContext.Session[SessionKey] as Member) : null; if (memberContext == null) { memberContext = new Member(); controllerContext.HttpContext.Session[SessionKey] = memberContext; } return memberContext; }
public void UpdateMemberOf(Member existingMember) { var success = false; if (existingMember != null) { using (var scope = new TransactionScope()) { var dbMember = _unitOfWork.MemberRepository.GetByID(existingMember.MemberId); if (dbMember != null) { var oldMemberOf = dbMember.MemberOf; dbMember.MemberOf = existingMember.MemberOf; _unitOfWork.MemberRepository.Update(dbMember); _unitOfWork.Save(); var dbMemberHistory = _unitOfWork.MemberMembershipRepository.Get( m => m.MemberId == existingMember.MemberId && m.MemberOf == oldMemberOf); if (dbMemberHistory != null) { dbMemberHistory.EndDate = DateTime.Now.Date; _unitOfWork.MemberMembershipRepository.Update(dbMemberHistory); _unitOfWork.Save(); } var dbMemberNewLog = _unitOfWork.MemberMembershipRepository.Get(m => m.MemberId == existingMember.MemberId && m.MemberOf == existingMember.MemberOf); if (dbMemberNewLog == null) { var newMemberHistory = new DataModel.Generated.MemberMembership { MemberId = existingMember.MemberId, StartDate = DateTime.Now.Date, MemberOf = existingMember.MemberOf }; _unitOfWork.MemberMembershipRepository.Insert(newMemberHistory); _unitOfWork.Save(); } //TODO: Insert new member history //TODO: Add record in history table scope.Complete(); success = true; } } } //return success; }
public RedirectToRouteResult UpdateMembership(MembershipHistoryViewModel viewModel, string memberOfOldValue) { if (viewModel.MemberOf != memberOfOldValue) { //existingMember.MemberOf = memberof; var member = new Member() {MemberId = viewModel.MemberId, MemberOf = viewModel.MemberOf}; _services.UpdateMemberOf(member); } return RedirectToAction("Members"); }
public ActionResult EditMember(Member aMember) { if (ModelState.IsValid) { if (aMember.MemberId > 0) { _services.UpdateMember(aMember); } else { Mapper.CreateMap<Member, NewMember>(); var newMember = Mapper.Map<Member, NewMember>(aMember); _services.AddMember(newMember); } TempData["message"] = string.Format("{0} has been saved", aMember.FullName); return RedirectToAction("Members"); } else { // there is something wrong with the data values return View(aMember); } }
public void UpdateMember(Member aMember) { var gender = string.IsNullOrEmpty(aMember.Gender) ? (char?) null : aMember.Gender[0]; using (var scope = new TransactionScope()) { var dbMember = _unitOfWork.MemberRepository.GetByID(aMember.MemberId); dbMember.MemberId = aMember.MemberId; dbMember.FirstName = aMember.FirstName; dbMember.LastName = aMember.LastName; dbMember.DOB = aMember.DateOfBirth; dbMember.Gender = gender.ToString(); dbMember.Phone = aMember.Phone; dbMember.Email = aMember.Email; //SpouseMemberId = aMember.SpouseMemberId, dbMember.IsHeadOfFamily = aMember.IsHeadOfFamily; //string.IsNullOrEmpty(MyString) ? (char?)null : MyString[0] //AT: We need to do manual mapping above. We can use code below but need to add the Ignore fields that we don't want updated // Mapper.CreateMap<Member, DataModel.Generated.Member > () //.ForMember(dest => dest.DOB, // opts => opts.MapFrom(src => src.DateOfBirth)); // var dbMember = Mapper.Map<Member, DataModel.Generated.Member>(aMember); _unitOfWork.MemberRepository.Update(dbMember); _unitOfWork.Save(); scope.Complete(); } }