public MethodResult UpdateLastUpdatedBy(Msd3AgentViewModel msd3AgentVM, string lastUpdatedByUser) { var methodResult = new MethodResult(); try { if (_context.Msd3agents.Where(x => x.Msd3Id == msd3AgentVM.Msd3Id && x.SenderId == msd3AgentVM.SenderId).Any()) { methodResult.SuccessFaliure = Enums.MethodResultOutcome.Failure; methodResult.Message = string.Format("Sender Name {0} already exists, please enter non-duplicate Sender and retry", msd3AgentVM.SenderId); return(methodResult); } _context.Msd3agents.Add(_entityToViewModelMapper.MapMsd3AgentViewModelToEntity(msd3AgentVM)); _context.Attach(UpdateMsd3AuditFields(msd3AgentVM, lastUpdatedByUser)).State = EntityState.Modified; _context.SaveChanges(); methodResult.SuccessFaliure = Enums.MethodResultOutcome.Success; methodResult.Message = "Sender added successfully"; } catch (Exception e) { methodResult.SuccessFaliure = Enums.MethodResultOutcome.Failure; methodResult.Message = "Error ocurred while updating Sender, please retry"; } return(methodResult); }
/// <param name="msd3AgentVM"></param> /// <param name="lastUpdatedByUser"></param> private Msd3 UpdateMsd3AuditFields(Msd3AgentViewModel msd3AgentVM, string lastUpdatedByUser) { var msd3Record = _context.Msd3.FirstOrDefault(m => m.Id == msd3AgentVM.Msd3Id); msd3Record.ModifiedDate = DateTime.Now; msd3Record.LastUpdatedBy = lastUpdatedByUser; return(msd3Record); }
public Msd3agents MapMsd3AgentViewModelToEntity(Msd3AgentViewModel msd3AgentVM) { return(new Msd3agents() { Id = msd3AgentVM.Id, Msd3Id = msd3AgentVM.Msd3Id, SenderId = msd3AgentVM.SenderId }); }
public IActionResult OnGet(int id) { Msd3agent = _msd3AgentDataService.GetMsd3AgentDetail(id); if (Msd3agent == null) { return(NotFound()); } return(Page()); }
public MethodResult Delete(Msd3AgentViewModel msd3AgentVM, string lastUpdatedByUser) { var methodResult = new MethodResult(); try { var msd3Agent = _context.Msd3agents.Find(msd3AgentVM.Id); if (msd3Agent != null) { _context.Attach(UpdateMsd3AuditFields(msd3AgentVM, lastUpdatedByUser)).State = EntityState.Modified; _context.Msd3agents.Remove(msd3Agent); _context.SaveChanges(); } methodResult.SuccessFaliure = Enums.MethodResultOutcome.Success; methodResult.Message = "Agent deleted successfully"; } catch (Exception e) { methodResult.SuccessFaliure = Enums.MethodResultOutcome.Failure; methodResult.Message = "Error ocurred while deleting Agent, please retry"; } return(methodResult); }