public async Task <ActionResult> PutCashAccount(string id, [FromBody] EditCashAccountModel model) { if (model is null) { return(BadRequest("can't process nulls")); } Guid acctId; try { acctId = Guid.Parse(id); } catch (Exception e) { ModelState.AddModelError(nameof(id), $"The Id provided is in an invalid state with error type {e.Message}"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } if (acctId.ToString() != model.Id) { return(BadRequest("The Ids are not the same")); } var test = await _service.GetById(acctId).ConfigureAwait(false); if (test is null) { return(new UnprocessableEntityObjectResult("Couldn't find the item you wish to update.")); } try { await _service.UpdateCashAccount(test, model, acctId); } catch (Exception ex) { ModelState.AddModelError("Error", $"{ex.Message}"); return(new UnprocessableEntityObjectResult(ModelState)); } return(NoContent()); }
public async Task UpdateCashAccount(CashAccount cashaccount, EditCashAccountModel model, Guid acctId) { try { cashaccount.AccountBalance = model.AccountBalance; cashaccount.AccountName = model.AccountName; cashaccount.CashAccountId = acctId; cashaccount.Currency = model.Currency; cashaccount.IsActivated = model.IsActivated; Update(cashaccount); await Context.SaveChangesAsync().ConfigureAwait(false); } catch (Exception e) { throw e; } }