// PUT api/account/5 public HttpResponseMessage Put(int id, [FromBody] PersonVm userProfileVm) { var user = this.personService.GetById(id); if (user.UserId != userService.CurrentUserId) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } if (ModelState.IsValid) { try { if (userProfileVm.ContactInformation.Email1 != user.ContactInformation.Email1) { emailHelper.SendEmailAddressChanged(user.FirstName, user.ContactInformation.Email1); } var person = userProfileVm.ToModel(this.userService.CurrentUserId); this.personService.Save(person); userProfileVm = PersonVm.FromModel(person); return(Request.CreateResponse(HttpStatusCode.Accepted)); } catch (Exception e) { emailHelper.SendErrorEmail(e); } } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
//public Admin ToModel(int userId){ // return new Admin // { // Id = this.Id, // DateVerified = this.DateVerified, // Person = this.Person.ToModel(userId), // VerificationNotes = this.VerificationNotes, // Verified = this.Verified // }; //} internal static AdminVm FromModel(Admin admin) { if (admin.Person == null) { admin.Person = new Person(); } return(new AdminVm { Id = admin.Id, DateVerified = admin.DateVerified, Person = PersonVm.FromModel(admin.Person), VerificationNotes = admin.VerificationNotes, Verified = admin.Verified }); }
public virtual ActionResult Index() { PersonVm userProfileVm = null; try { var person = this.personService.Get(this.webSecurityService.CurrentUserId); if (person != null) { userProfileVm = PersonVm.FromModel(person); } else { userProfileVm = new PersonVm(); } return(View(userProfileVm)); } catch (Exception e) { this.emailHelper.SendErrorEmail(e as Exception); } return(View(WENEEDUHAVE.Error.Views.Index)); }