public WorkingTimeDTO Replace(WorkingTimeEntity newEntity) { var transaction = _humanManagerContext.Database.BeginTransaction(); WorkingTimeEntity oldEntity = null; try { oldEntity = _humanManagerContext.WorkingTimes.Where(wt => wt.Id == newEntity.Id) .Include(wt => wt.WorkingTimeDetails) .SingleOrDefault(); oldEntity = _wtUpdater.DoUpdate(oldEntity, newEntity); _humanManagerContext.SaveChanges(); transaction.Commit(); WorkingTimeDTO dto = _mapper.Map <WorkingTimeDTO>(oldEntity); return(dto); } catch { transaction.Rollback(); return(null); } }
public ActionResult <Api <WorkingTimeDTO> > New(WorkingTimeEntity newEntity) { WorkingTimeDTO dto = _workingTimeService.Save(newEntity); Api <WorkingTimeDTO> result = new Api <WorkingTimeDTO>(200, dto, "Add Success"); return(Ok(result)); }
public ActionResult <Api <WorkingTimeDTO> > Edit(long id, WorkingTimeEntity newEntity) { newEntity.Id = id; newEntity.WorkingTimeDetails.ForEach(wtd => wtd.WorkingTimeId = id); WorkingTimeDTO dto = _workingTimeService.Replace(newEntity); Api <WorkingTimeDTO> result = new Api <WorkingTimeDTO>(200, dto, "Edit Success"); return(Ok(result)); }
public WorkingTimeDTO Save(WorkingTimeEntity newEntity) { var transaction = _humanManagerContext.Database.BeginTransaction(); WorkingTimeEntity entity = null; try { entity = _humanManagerContext.WorkingTimes.Add(newEntity).Entity; _humanManagerContext.SaveChanges(); transaction.Commit(); WorkingTimeDTO dto = _mapper.Map <WorkingTimeDTO>(entity); return(dto); } catch { transaction.Rollback(); return(null); } }