public ActionResult Edit(Member member) { Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id); if (currentMember != null) { if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14) { ModelState.AddModelError("Seniority", "We count your seniority from age of 14 only"); } if (ModelState.IsValid) { currentMember.Name = member.Name; currentMember.Seniority = member.Seniority; currentMember.IsProgrammer = member.IsProgrammer; currentMember.CityId = member.CityId; currentMember.BirthDate = member.BirthDate; currentMember.IsAcceptConditions = member.IsAcceptConditions; return RedirectToAction("Index"); } else { return View(new EditMemberViewModel {MemberData = member, Cities = CityRepository.Cities}); } } else return View("ErrorPage", string.Format("{0} not found", member.Id)); }
public ActionResult Edit(Member member) { try { if ((member != null) && (member.Id != null)) { Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id); if (currentMember != null) { if (member.Id != member.newId) //The Id changed { currentMember.Id = member.newId; } currentMember.Name = member.Name; currentMember.Seniority = member.Seniority; currentMember.IsAProgrammer = member.IsAProgrammer; return RedirectToAction("Index"); } } throw new Exception(String.Format("{0} Not found", member.Id)); } catch (Exception ex) { return new ContentResult { Content = string.Format("Error: {0}", ex.Message) }; } }
public static ValidationResult IsValid_BirthDate_Seniority(Member member) { if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14) { return new ValidationResult("We count your seniority from age of 14 only"); } return null; }
public ActionResult Register(Member member) { if (ModelState.IsValid) { Repository.Add(member); return RedirectToAction("Index"); } else { return View(new EditMemberViewModel { MemberData = member, Cities = CityRepository.Cities }); } }
public ActionResult Delete(Member member) { Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id); if (currentMember != null) { Repository.Members.Remove(currentMember); return RedirectToAction("Index"); } else return new ContentResult { Content = string.Format("{0} not found", member.Id) }; }
public ActionResult Edit(Member member) { Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id); if (member != null) { currentMember.Name = member.Name; currentMember.Seniority = member.Seniority; return RedirectToAction("Index"); } else return new ContentResult { Content = string.Format("{0} not found", member.Id) }; }
public ActionResult SaveMember(Member editedMember) { Member member = Repository.Members.FirstOrDefault(m => m.Id == editedMember.Id); if (member != null) { member.Name = editedMember.Name; member.Seniority = editedMember.Seniority; return RedirectToAction("Index"); } else return new ContentResult { Content = string.Format("{0} not found", editedMember.Id) }; }
public ActionResult Edit(Member member) { Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id); if (member != null) { currentMember.Name = member.Name; currentMember.Seniority = member.Seniority; currentMember.IsProgrammer = member.IsProgrammer; currentMember.CityId = member.CityId; return RedirectToAction("Index"); } else return View("ErrorPage", string.Format("{0} not found", member.Id)); }
public ActionResult Edit(Member member, int prevId) { Debug.WriteLine("Query String: {0}", Request.QueryString); Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == prevId); if (member != null) { currentMember.Id = member.Id; currentMember.Name = member.Name; currentMember.Seniority = member.Seniority; return RedirectToAction("Index"); } else return new ContentResult { Content = string.Format("{0} not found", prevId) }; }
public ActionResult Register(Member member) { if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14) { ModelState.AddModelError("Seniority", "We count your seniority from age of 14 only"); } if (ModelState.IsValid) { Repository.Add(member); return RedirectToAction("Index"); } else { return View(new EditMemberViewModel { MemberData = member, Cities = CityRepository.Cities }); } }
public ActionResult Edit(Member member) { Member memberFound = Repository.Members.FirstOrDefault(m => m.Id == member.Id); if (memberFound != null) { if (member.action.Equals("Edit")) return View(memberFound); else //It contains info already { memberFound.Name = member.Name; memberFound.Seniority = member.Seniority; memberFound.IsProgrammer = member.IsProgrammer; return RedirectToAction("Index"); } } else return View("ErrorPage", string.Format("{0} not found", member.Id)); // return new ContentResult { Content = string.Format("{0} not found", id) }; }
public ActionResult Edit(Member member) { Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id); if (currentMember != null) { //if (member.Id < 100 || member.Id > 9999) // ModelState.AddModelError("Id", "Id value must be 100-9999"); if (member.Name.Length < 3) ModelState.AddModelError("Name", "Minimum name length is 3 characters"); if (member.Name.Length > 12) ModelState.AddModelError("Name", "Maximum name length is 12 characters"); if (member.Seniority < 0 || member.Seniority > 50) ModelState.AddModelError("Seniority", "Seniority 0-50"); if (Underage(member.BirthDate, 18)) ModelState.AddModelError("BirthDate", "You are under 18 kid. Sorry, no can do."); if (Overage(member.BirthDate, 100)) ModelState.AddModelError("BirthDate", "You are an old fart. Sorry, no can do."); if (ModelState.IsValid) { currentMember.Name = member.Name; currentMember.Seniority = member.Seniority; currentMember.IsProgrammer = member.IsProgrammer; currentMember.CityId = member.CityId; currentMember.BirthDate = member.BirthDate; currentMember.IsAcceptConditions = member.IsAcceptConditions; return RedirectToAction("Index"); } else { EditMemberViewModel emvm = new EditMemberViewModel { MemberData=member, Cities=CityRepository.Cities, }; return View(emvm); } } else return View("ErrorPage", string.Format("{0} not found", member.Id)); }
public ActionResult Register(Member member) { if (member.Name.Length < 2 || member.Name.Length > 12) { ModelState.AddModelError("Name", "Name: 2-12 characters"); } if (DateTime.Today.Year - member.BirthDate.Year < 18) { ModelState.AddModelError("BirthDate", "You are too young. Try tomorrow."); } else if (DateTime.Today.Year - member.BirthDate.Year > 100) { ModelState.AddModelError("BirthDate", "You are too old. Have you great-grandsons?"); } if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14) { ModelState.AddModelError("Seniority", "We count your seniority from age of 14 only"); } if (member.CityId == -1) { ModelState.AddModelError("CityId", "You must select a city"); } if (!member.IsAcceptConditions && !(!member.IsProgrammer && member.CityId == 7000)) { ModelState.AddModelError("IsAcceptConditions", "You must accept our conditions"); } if (ModelState.IsValid) { Repository.Add(member); return RedirectToAction("Index"); } else { return View(new EditMemberViewModel { MemberData = member, Cities = CityRepository.Cities }); } }
public ActionResult Register(Member m) { Repository.Add(m); // return View("RegistrationPage"); return RedirectToAction("Register"); }
public static void Add(Member m) { Members.Add(m); }
public ActionResult Register(Member m) { Repository.Add(m); return RedirectToAction("Register"); }
public ActionResult QueryMember() { Member m = new Member(); return View("ShowMemberPage", m); }
//public ActionResult Edit(int id) //{ // Member member = Repository.Members.FirstOrDefault(m => m.Id == id); // if (member != null) // { // return View(member); // } // else // return View("ErrorPage", string.Format("{0} not found", id)); //} //[HttpPost] //public ActionResult Edit(Member member) //{ // Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id); // if (member != null) // { // currentMember.Name = member.Name; // currentMember.Seniority = member.Seniority; // currentMember.IsProgrammer = member.IsProgrammer; // return RedirectToAction("Index"); // } // else // return View("ErrorPage", string.Format("{0} not found", member.Id)); //} public ActionResult Edit() { if (Request.HttpMethod == "GET") { #region GET Code #region Get id int id; if (Request["id"] != null) { id = int.Parse(Request["id"]); } else { string[] UrlParts = Request.RawUrl.Split('/'); id = int.Parse(UrlParts[UrlParts.Length - 1]); } #endregion #region Get member Member member = Repository.Members.FirstOrDefault(m => m.Id == id); if (member != null) { return View(member); } else return View("ErrorPage", string.Format("{0} not found", id)); #endregion #endregion } else { #region POST Code #region Binding Member member = new Member { Id=int.Parse(Request["id"]), Name=Request["Name"], Seniority = int.Parse(Request["Seniority"]), IsProgrammer=bool.Parse(Request["IsProgrammer"].Split(',')[0]), }; #endregion #region Update Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id); if (currentMember != null) { currentMember.Name = member.Name; currentMember.Seniority = member.Seniority; currentMember.IsProgrammer = member.IsProgrammer; return RedirectToAction("Index"); } else return View("ErrorPage", string.Format("{0} not found", member.Id)); #endregion #endregion } }
public static void Edit(Member m, Member newMember) { m.Id = newMember.Id; m.Name = newMember.Name; m.Seniority = newMember.Seniority; }
public ActionResult Edit(Member member) { Member currentMember = Repository.Members.FirstOrDefault(m => m.Id == member.Id); if (member != null) { if (member.Name==null || member.Name.Length < 2 || member.Name.Length > 12) { ModelState.AddModelError("Name", "Name: 2-12 characters" ); } if (DateTime.Today.Year - member.BirthDate.Year < 18) { ModelState.AddModelError("BirthDate", "You are too young. Try tomorrow."); } else if (DateTime.Today.Year - member.BirthDate.Year > 100) { ModelState.AddModelError("BirthDate", "You are too old. Have you great-grandsons?"); } if (DateTime.Today.Year - member.BirthDate.Year - member.Seniority < 14) { ModelState.AddModelError("Seniority", "We count your seniority from age of 14 only"); } if (member.CityId == -1) { ModelState.AddModelError("CityId", "You must select a city"); } if (!member.IsAcceptConditions && !(!member.IsProgrammer && member.CityId==7000)) { ModelState.AddModelError("IsAcceptConditions", "You must accept our conditions"); } if (ModelState.IsValid) { currentMember.Name = member.Name; currentMember.Seniority = member.Seniority; currentMember.IsProgrammer = member.IsProgrammer; currentMember.CityId = member.CityId; currentMember.BirthDate = member.BirthDate; currentMember.IsAcceptConditions = member.IsAcceptConditions; return RedirectToAction("Index"); } else { return View(new EditMemberViewModel {MemberData = member, Cities = CityRepository.Cities}); } } else return View("ErrorPage", string.Format("{0} not found", member.Id)); }
public MemberViewModel() { MemberData = new Member(); }