public WorkItemViewModel CreateOrUpdate(WorkItemViewModel model, DateTime?dateChanged) { var workItem = _mapper.Map <WorkItem>(model); var result = _workRepository.Find(workItem.Id); if (result == null) { workItem.CreatedBy = model.CreatedBy; workItem.UpdatedAt = DateTime.Now; _workRepository.Add(workItem); if (dateChanged != null) { workItem = PutDateByStatus(workItem, dateChanged.GetValueOrDefault()); } var worksheet = CreateOrUpdateSerializable(workItem); _workSheetRepository.Add(worksheet); _transaction.Commit(); var viewModel = _mapper.Map <WorkItemViewModel>(workItem); return(viewModel); } else { result.UpdatedBy = model.CreatedBy; var week = _mapper.Map <Week>(model.Week); var assignee = _mapper.Map <Assignee>(model.Assignee); var team = assignee != null ? assignee.Team : model.Team; result.WeekId = week.Id; result.SetStatus(model.Status); result.SetType(model.Type); result.SetAcceptanceReleaseDate(model.AcceptanceReleaseDate); result.SetProductionReleaseDate(model.ProductionReleaseDate); result.SetStartImpedimentDate(model.StartImpedimentDate); result.SetEndImpedimentDate(model.EndImpedimentDate); result.SetObservations(model.Observations); result.SetTeam(team); result.AssigneeId = assignee?.Id; if (dateChanged != null) { result = PutDateByStatus(result, dateChanged.GetValueOrDefault()); } _workRepository.Update(result); var worksheet = CreateOrUpdateSerializable(result); _workSheetRepository.Update(worksheet); _transaction.Commit(); var viewModel = _mapper.Map <WorkItemViewModel>(result); return(viewModel); } }
public WorkEditModel BuildEdit(Guid id) { var work = workRepository.Find(id); var form = new WorkForm() { Description = work.Description, EngineType = work.EngineType }; return(new WorkEditModel(id, form, engineTypesListModelBuilder.Build())); }
public WorkValidationResult ValidateOnEdit(Guid id, WorkForm form, ModelStateDictionary modelState) { Validate(form, modelState); var work = workRepository.Find(id); if (work == null) { throw new Exception("Работа не найдена"); } return(new WorkValidationResult(modelState, work)); }
public void Create(Work work) { bool anyWork = workRepositiory.Find(x => x.Name.ToUpper().Equals(work.Name.ToUpper())).Any(); if (anyWork) { throw new DomainException("Já existe uma obra com o nome informado"); } work.EnableWork(); workRepositiory.Save(work); }
public ActionResult Details(int id) { try { ViewBag.WorkItems = _workRepository.Find(id); } catch (Exception exception) { ViewBag.Message = exception.Message; _appLogRepository.Log(exception); } return(View()); }
public WorkItemModel Build(Guid id) { var item = workRepository.Find(id); if (item == null) { throw new Exception("Работа не найдена"); } return(new WorkItemModel() { Id = item.Id, Description = item.Description, EngineType = item.EngineType }); }
public ICollection <Work> GetWorks() { return(workRepository.Find(work => work.Actived).ToList()); }