public async Task <IActionResult> Update([FromBody] ProposalVM vm) { var getResult = await _bo.ReadAsync(vm.Id); if (!getResult.Success) { return(InternalServerError(getResult.Exception)); } var item = getResult.Result; if (item == null) { return(NotFound()); } if (vm.CompareToModel(item)) { return(NotModified()); } item = vm.ToProposal(item); var updateResult = await _bo.UpdateAsync(item); if (!updateResult.Success) { return(InternalServerError(updateResult.Exception)); } return(Ok()); }
public async Task <IActionResult> Edit(Guid id, ProposalVM vm) { if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync(id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var result = getOperation.Result; if (!vm.CompareToModel(result)) { result = vm.ToProposal(result); var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception); return(View(vm)); } return(OperationSuccess("The record was successfully updated.")); } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> CreateAsync([FromBody] ProposalVM vm) { var newProposal = vm.ToProposal(); var result = await _bo.CreateAsync(newProposal); if (!result.Success) { return(InternalServerError(result.Exception)); } return(Created(Request.Path.Value, null)); }
public async Task <IActionResult> New(ProposalVM vm) { if (ModelState.IsValid) { var model = vm.ToProposal(); var createOperation = await _bo.CreateAsync(model); if (!createOperation.Success) { return(OperationErrorBackToIndex(createOperation.Exception)); } return(OperationSuccess("The record was successfully created.")); } return(View(vm)); }