public static Member CopyToEntity(this EditMemberViewModel model, Member member) { member.FirstName = model.FirstName; member.LastName = model.LastName; member.AddressLine_1 = model.AddressLine_1; member.AddressLine_2 = model.AddressLine_2; member.AltPhone = model.AltPhone; member.City = model.City; member.EmergencyName = model.EmergencyName; member.EmergencyPhone = model.EmergencyPhone; member.LastMedical = model.LastMedical; member.Phone = model.Phone; //member.PrimaryEmail = model.PrimaryEmail; member.RetractHours = model.RetractHours; //member.SecondaryEmail = model.SecondaryEmail; member.MemberSince = model.MemberSince; member.TotalHours = model.TotalHours; member.Zip = model.Zip; return(member); }
public ActionResult Edit(EditMemberViewModel model) { List<Role> roles = _dataService.GetAllRoles(); if (ModelState.IsValid) { Member origMember = _dataService.GetMember(model.Id); //model.ConvertToEntity(); model.CopyToEntity(origMember); if (User.IsInRole(UserRoles.Admin.ToString())) { origMember.Roles = model.MemberRoles.Select(id => roles.FirstOrDefault(cr => cr.Id == id)).ToList(); origMember.Status = model.Status; } _dataService.UpdateMember(origMember); return RedirectToAction("Details", new { id = model.Id }); } //var errors = from v in ModelState.Values // where v.Errors.Count > 0 // select v.Errors; model.ClubRoles = roles; return View(ViewNames.EditMember, model); }
public static Member ConvertToEntity(this EditMemberViewModel model) { Member member = new Member(); return(model.CopyToEntity(member)); }
public ActionResult Edit(int? id) { int memberId = 0; ProfileCommon profile = HttpContext.Profile as ProfileCommon; if (profile == null) RedirectToAction("LogOn", "Account"); // make sure member information is edited by self or admin only if (id == null) { memberId = profile.MemberId; } else { if (id == profile.MemberId) { memberId = profile.MemberId; } else { if (User.IsInRole(FlyingClub.Common.UserRoles.Admin.ToString())) memberId = (int)id; else throw new HttpException(403, "Operation is not authorized."); } } Member member = _dataService.GetMember(memberId); EditMemberViewModel model = new EditMemberViewModel(member); model.ClubRoles = _dataService.GetAllRoles(); model.MemberRoles = member.Roles.Select(r => r.Id).ToList(); return View(ViewNames.EditMember, model); }
public ActionResult Create(EditMemberViewModel model) { if (ModelState.IsValid) { Member member = model.ConvertToEntity(); member.MemberSince = DateTime.Now; Login login = null; if (model.LoginId == 0) login = _dataService.GetLoginByUsername(model.Username); else login = _dataService.GetLoginById(model.LoginId); if (login == null) { ModelState.AddModelError("Username", String.Format("Username '{0}' can not be found in the database", model.Username)); model.ClubRoles = _dataService.GetAllRoles(); return View(ViewNames.CreateMember, model); } member.LoginId = login.Id; if (model.MemberRoles != null && model.MemberRoles.Count > 0) { List<Role> allRoles = _dataService.GetAllRoles(); member.Roles = new List<Role>(); foreach (int roleId in model.MemberRoles) member.Roles.Add(allRoles.FirstOrDefault(r => r.Id == roleId)); } member.Status = model.Status; _dataService.SaveMember(member); return RedirectToAction("Details", new { id = member.Id }); } model.MemberRoles = new List<int>(); model.ClubRoles = _dataService.GetAllRoles(); return View(ViewNames.EditMember, model); }
public ActionResult Create(int? loginId) { EditMemberViewModel viewModel = new EditMemberViewModel(); viewModel.ClubRoles = _dataService.GetAllRoles(); viewModel.Status = MemberStatus.Pending.ToString(); viewModel.MemberRoles = new List<int>(); if (loginId != null) { Login login = _dataService.GetLoginById((int)loginId); viewModel.LoginId = login.Id; viewModel.Username = login.Username; } return View(ViewNames.CreateMember, viewModel); }
public ActionResult EditMyProfile(EditMemberViewModel model) { if (ModelState.IsValid) { Member origMember = _dataService.GetMember(model.Id); origMember.FirstName = model.FirstName; origMember.LastName = model.LastName; origMember.Phone = model.Phone; origMember.AltPhone = model.AltPhone; origMember.AddressLine_1 = model.AddressLine_1; origMember.AddressLine_2 = model.AddressLine_2; origMember.City = model.City; origMember.State = model.State; origMember.Zip = model.Zip; origMember.LastMedical = model.LastMedical; origMember.TotalHours = model.TotalHours; origMember.RetractHours = model.RetractHours; origMember.EmergencyName = model.EmergencyName; origMember.EmergencyPhone = model.EmergencyPhone; // emails updated in separate view //origMember.PrimaryEmail = model.PrimaryEmail; //origMember.SecondaryEmail = model.SecondaryEmail; _dataService.UpdateMember(origMember); return RedirectToAction("Details", new { id = model.Id }); } // use this to collect errors and log them //var errors = from v in ModelState.Values // where v.Errors.Count > 0 // select v.Errors; return View(model); }
public ActionResult EditMyProfile() { ProfileCommon profile = HttpContext.Profile as ProfileCommon; if (profile == null) throw new HttpException(404, "Member not found"); Member member = _dataService.GetMember(profile.MemberId); EditMemberViewModel model = new EditMemberViewModel(member); return View(model); }