public async Task <IActionResult> Edit(InputModels.QuotesInput input) { if (ModelState.IsValid) { var serviceResponse = await QuoteRepository.Edit(input); return(await ForumViewResult.RedirectFromService(this, serviceResponse)); } return(ForumViewResult.RedirectToReferrer(this)); }
public async Task <ServiceModels.ServiceResponse> Edit(InputModels.QuotesInput input) { var serviceResponse = new ServiceModels.ServiceResponse(); foreach (var quoteInput in input.Quotes) { var record = (await Records()).FirstOrDefault(r => r.Id == quoteInput.Id); if (record is null) { serviceResponse.Error($@"No record was found with the id '{quoteInput.Id}'."); } if (serviceResponse.Success) { if (quoteInput.Approved != record.Approved) { record.Approved = quoteInput.Approved; DbContext.Update(record); } if (quoteInput.OriginalBody != record.OriginalBody) { record.OriginalBody = quoteInput.OriginalBody; var processedMessageInput = await MessageRepository.ProcessMessageInput(serviceResponse, quoteInput.OriginalBody); record.DisplayBody = processedMessageInput.DisplayBody; DbContext.Update(record); } if (serviceResponse.Success) { DbContext.SaveChanges(); serviceResponse.Message = $"Changes saved."; } } } return(serviceResponse); }