Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public async Task <bool> AddAsync(WorkDTO workDTO)
        {
            var work   = _mapper.Map <WorkDTO, Work>(workDTO);
            var result = await _workRepository.Add(work);

            return(result);
        }
Exemplo n.º 3
0
        public ActionResult Create(WorkEditViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Work work = Mapper.Map <WorkEditViewModel, Work>(viewModel);
                work.UserID = User.Identity.GetUserId();
                _workRepository.Add(work);
                _workRepository.Save();

                return(Json(new { success = true }));
            }

            return(PartialView("_Create"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Work(WorkViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                if (user.Status != UserStatus.Stays)
                {
                    ModelState.AddModelError(string.Empty, "Aktualnie nie możesz pracować.");
                }
                else if (user.ActionPoints < model.Work.Hours)
                {
                    ModelState.AddModelError(string.Empty, "Nie masz siły na taką pracę!");
                }
                else
                {
                    var work = new Work()
                    {
                        UserId = user.Id,
                        Start  = DateTime.UtcNow,
                        End    = DateTime.UtcNow.AddHours(model.Work.Hours),
                        Hours  = model.Work.Hours
                    };

                    user.Status = UserStatus.Work;
                    await _userManager.UpdateAsync(user);

                    _workRepository.Add(work);

                    model.Work         = work;
                    model.WorkProgress = true;
                }
            }

            return(View(model));
        }