public async Task <ActionResult <AccountVM> > Patch(Guid id, [FromBody] JsonPatchDocument <AccountPatchVM> patchDocument) { // Validation if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // BLL User currentUser = await userManager.GetUserAsync(User); AccountBLL bll = new AccountBLL(this.unitOfWork, currentUser); // Retrieve account Account account = await bll.GetAccountById(id); // Validation if (account == null) { return(NotFound()); } // Mapping AccountPatchVM accountPatchVM = this.mapper.Map <AccountPatchVM>(account); // Patch patchDocument.ApplyTo(accountPatchVM, ModelState); // Validation after patch if (!TryValidateModel(account)) { return(BadRequest(ModelState)); } // Mapping this.mapper.Map(accountPatchVM, account); // Trigger update await bll.UpdateAccount(account); return(Ok(this.mapper.Map <Account, AccountVM>(account))); }
public JsonResult AccountEdit(string Id, string title, string contents) { JsonResult js = new JsonResult(); Account loginAccount = membership.GetUser(); //未登录 if (loginAccount == null) { js.Data = "false"; return(js); } Account picOld = accountBll.GetAccountById(Guid.Parse(Id)); picOld.Mobile = title; picOld.Password = contents; accountBll.EditAccount(); js.Data = "true"; return(js); }