public CustomerNotesDto UpdateCustomerNotes(CustomerNotesDto model) { try { var oldCustomerNotes = _context.customersnotes.FirstOrDefault(x => x.CustomerNotesId == model.CustomerNotesId); var updatedCustomerNotes = Mapper.Map <customersnote>(model); updatedCustomerNotes.Modified = DateTime.Now; updatedCustomerNotes.ModifiedBy = model.ModifiedBy; updatedCustomerNotes.Created = oldCustomerNotes.Created; updatedCustomerNotes.CreatedBy = oldCustomerNotes.CreatedBy; updatedCustomerNotes.CustomerId = model.NotesCustomerId; _context.Entry(oldCustomerNotes).CurrentValues.SetValues(updatedCustomerNotes); _context.SaveChanges(); return(model); } catch (DbEntityValidationException ex) { var errorMsg = EisHelper.ParseDbEntityValidationException(ex); _logger.LogError(LogEntryType.CustomerService, errorMsg, ex.StackTrace); throw ex; } catch (Exception ex) { _logger.LogError(LogEntryType.CustomerService, EisHelper.GetExceptionMessage(ex), ex.StackTrace); throw ex; } }
public CustomerNotesDto CreateCustomerNotes(CustomerNotesDto model) { try { var customerNotes = Mapper.Map <customersnote>(model); customerNotes.Created = DateTime.UtcNow; customerNotes.CreatedBy = model.ModifiedBy; customerNotes.ModifiedBy = null; customerNotes.CustomerId = model.NotesCustomerId; _context.customersnotes.Add(customerNotes); _context.SaveChanges(); model.CustomerNotesId = customerNotes.CustomerNotesId; return(model); } catch (DbEntityValidationException ex) { var errorMsg = EisHelper.ParseDbEntityValidationException(ex); _logger.LogError(LogEntryType.CustomerService, errorMsg, ex.StackTrace); throw ex; } catch (Exception ex) { _logger.LogError(LogEntryType.CustomerService, EisHelper.GetExceptionMessage(ex), ex.StackTrace); throw ex; } }
public ActionResult SaveNotes(CustomerNotesDto model) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(e => e.Errors.Select(x => x.ErrorMessage)); ModelState.AddModelError("", string.Join("<br/>", errors)); return(View("Edit", model)); } // save the message template model.ModifiedBy = User.Identity.Name; if (model.CustomerNotesId == -1) { model = _customerService.CreateCustomerNotes(model); } else { model = _customerService.UpdateCustomerNotes(model); } TempData["Message"] = "Changes have been successfully saved!"; return(RedirectToAction("edit", new { id = model.NotesCustomerId })); }