public ActionResult Edit([Bind(Include = "MemberID,MemberSubscriptionTypeID,FirstName,LastName,IdentityType,EmailAddress,TelephoneHome,TelephoneOffice,TelephoneMobile,CountryID,StateID,Gender,Ethnicity,DateOfBirth,ActiveIndicator,RenewalDate,AddressID,DateInserted,DateUpdated,USR")] Member member) { MemberValidator validator = new MemberValidator(); if (ModelState.IsValid && validator.Validate(member).IsValid) { db.Entry(member).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ValidationResult results = validator.Validate(member); IList <ValidationFailure> failures = results.Errors; StringBuilder sb = new StringBuilder(); foreach (var e in results.Errors) { ModelState.AddModelError(e.PropertyName + "Error", e.ErrorMessage); sb.AppendLine(e.ErrorMessage); } ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", member.CountryID); ViewBag.StateID = new SelectList(db.CountryStates, "StateID", "StateName", member.StateID); ViewBag.AddressID = new SelectList(db.Addresses, "AddressID", "AddressType", member.AddressID); ViewBag.MemberSubscriptionTypeID = new SelectList(db.MemberSubscriptionTypes, "MemberSubscriptionTypeID", "MemberSubscriptionTypeCode", member.MemberSubscriptionTypeID); return(View(member)); }
public ActionResult Create([Bind(Include = "ASPUserId,MemberID,MemberSubscriptionTypeID,FirstName, LastName,IdentityType,EmailAddress,TelephoneHome,TelephoneOffice,TelephoneMobile,CountryID,StateID,Gender,Ethnicity,DateOfBirth,ActiveIndicator,RenewalDate,AddressID,DateInserted,DateUpdated,USR")] Member member) { MemberValidator validator = new MemberValidator(); if (ModelState.IsValid && validator.Validate(member).IsValid) { member.AddressID = -1; member.DateInserted = DateTime.Today; member.DateUpdated = DateTime.Today; member.ASPUserId = User.Identity.GetUserId(); member.USR = User.Identity.GetUserName(); member.ActiveIndicator = true; db.Members.Add(member); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } return(RedirectToAction("Index", "Home")); } ValidationResult results = validator.Validate(member); IList <ValidationFailure> failures = results.Errors; StringBuilder sb = new StringBuilder(); foreach (var e in results.Errors) { ModelState.AddModelError(e.PropertyName, e.ErrorMessage); ModelState.AddModelError(e.PropertyName + "Error", e.ErrorMessage); sb.AppendLine(e.ErrorMessage); } ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", member.CountryID); ViewBag.StateID = new SelectList(db.CountryStates, "StateID", "StateName", member.StateID); ViewBag.MemberSubscriptionTypeID = new SelectList(db.MemberSubscriptionTypes, "MemberSubscriptionTypeID", "MemberSubscriptionTypeCode", member.MemberSubscriptionTypeID); return(View(member)); }
public IActionResult AddMember([FromBody] Member member) { var validator = new MemberValidator(); if (validator.Validate(member).IsValid) { _memberService.AddMember(member); return(Ok()); } return(BadRequest()); }
public IActionResult UpdateMember([FromBody] Member member, int id) { var validator = new MemberValidator(); if (validator.Validate(member).IsValid) { member.Id = id; _memberService.UpdateMember(member); return(Ok()); } return(BadRequest()); }
public async Task Validate_TwoMembers(bool valid, string email1, string email2) { using (var provider = await CreateProvider()) { var context = provider.GetRequiredService <IContext>(); var access = provider.GetRequiredService <IContextLock>(); var worlds = provider.GetRequiredService <IWorldRepository>(); var entries = provider.GetRequiredService <IEntryRepository>(); IValidator <Member> validator = new MemberValidator(entries, worlds); var world = new World(); using (var handle = await access.Write()) { var one = new Member { World = world, Email = new EmailAddress(email1) }; world.Members = new HashSet <Member> { one }; context.Add(one); await handle.Finish(); } using (await access.Read()) { var two = new Member { World = world, Email = new EmailAddress(email2) }; var target = new ValidationTarget <Member>(two); validator.Validate(target); Assert.Equal(valid, !target.GetResult().HasErrors); } } }
public async Task Validate_OneMember() { using (var provider = await CreateProvider()) { var access = provider.GetRequiredService <IContextLock>(); var worlds = provider.GetRequiredService <IWorldRepository>(); var entries = provider.GetRequiredService <IEntryRepository>(); IValidator <Member> validator = new MemberValidator(entries, worlds); var member = new Member { World = new World() }; using (await access.Read()) { var target = new ValidationTarget <Member>(member); validator.Validate(target); Assert.False(target.GetResult().HasErrors); } } }