Exemplo n.º 1
0
        public TaskModelDto Add(TaskModelDto dto, EmployeeUser currentUser)
        {
            TaskModel TaskModel = Map(dto);

            TaskModel.CreatedDate = DateTime.Now;
            var saved = _context.TaskModels.Add(TaskModel);

            _context.TaskUsers.Add(new TaskUser()
            {
                TaskModelId = TaskModel.Id,
                UserId      = currentUser.Id
            });
            _context.SaveChanges();

            var estHist = new EstimateHistory()
            {
                Reason      = "Создание задачи",
                NewValue    = dto.EstimatedTime,
                OldValue    = 0,
                TaskModelId = saved.Entity.Id,
                UserId      = currentUser.Id,
                Date        = DateTime.Now,
            };

            _context.EstimateHistories.Add(estHist);
            _context.SaveChanges();
            return(Map(TaskModel));
        }
        public async Task <IActionResult> Post([FromBody] TaskModelDto task)
        {
            task.Id = Guid.Empty;
            task.Id = await _service.AddAsync(task);

            return(CreatedAtAction("Get", new { id = task.Id }, task));
        }
Exemplo n.º 3
0
        public async ValueTask UpdateAsync(TaskModelDto item)
        {
            var domainItem = _mapper.Map <TaskModel>(item);

            _repository.Update(domainItem);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <Guid> AddAsync(TaskModelDto item)
        {
            var domainItem = _mapper.Map <TaskModel>(item);

            _repository.Insert(domainItem);

            await _context.SaveChangesAsync();

            return(domainItem.Id);
        }
        public async Task <IActionResult> Patch(Guid id, [FromBody] TaskModelDto task)
        {
            if (id != task.Id)
            {
                return(BadRequest());
            }

            if (await _service.Exists(id))
            {
                await _service.UpdateAsync(task);
            }
            else
            {
                return(NotFound());
            }

            return(NoContent());
        }
Exemplo n.º 6
0
        //public List<TaskModelDto> GetTaskModelByManager(string id)
        //{
        //    return _context.TaskModels

        //        .Include(x => x.Manager).Where(x=>x.ManagerId == id).ToList().Select(x => Map(x)).ToList();
        //}

        public TaskModelDto Update(TaskModelDto dto, EmployeeUser user)
        {
            var       oldTime   = _context.TaskModels.Where(x => x.Id == dto.Id).FirstOrDefault().EstimatedTime;
            TaskModel TaskModel = Map(dto);

            _context.TaskModels.Update(TaskModel);

            if (oldTime != dto.EstimatedTime)
            {
                foreach (var userTask in _context.TaskUsers.Where(x => x.TaskModelId == dto.Id))
                {
                    var not = new Notification()
                    {
                        Date = DateTime.Now,
                        Name = "Оценочное время было изменено",
                        New  = true,
                        Text = $"Оценочное время задачи с номером {dto.TaskNumber} проекта {dto.Project} было изменено. " + Environment.NewLine +
                               $"Старое значение: {oldTime} " + Environment.NewLine +
                               $"Новое значение: {dto.EstimatedTime} " + Environment.NewLine +
                               $"Изменил: {user.FIO} " + Environment.NewLine +
                               $"Комментарий: {dto.ChangeEstimateReason}",
                        UserId = userTask.UserId
                    };
                    _context.Notifications.Add(not);
                }

                var estHist = new EstimateHistory()
                {
                    Reason      = dto.ChangeEstimateReason,
                    NewValue    = dto.EstimatedTime,
                    OldValue    = oldTime,
                    TaskModelId = dto.Id,
                    UserId      = user.Id,
                    Date        = DateTime.Now
                };
                _context.EstimateHistories.Add(estHist);
            }

            _context.SaveChanges();
            return(Map(TaskModel, true));
        }
Exemplo n.º 7
0
        public TaskModel Map(TaskModelDto dto)
        {
            TaskModel user = _context.TaskModels.FirstOrDefault(x => x.Id == dto.Id);

            if (user == null)
            {
                user = new TaskModel();
            }

            user.TaskNumber      = dto.TaskNumber;
            user.ProjectId       = dto.ProjectId;
            user.TaskName        = dto.TaskName;
            user.TaskDescription = dto.TaskDescription;
            user.Type            = (TaskType)dto.Type;
            user.Priority        = (TaskPriority)dto.Priority;
            user.Complexity      = (TaskComplexity)dto.Complexity;
            user.Status          = (TaskStatus)dto.Status;
            user.EstimatedTime   = dto.EstimatedTime;
            user.ParentId        = dto.ParentId == -1?null: dto.ParentId;
            user.Date            = dto.Date;

            return(user);
        }
 public TaskModelDto Update([FromBody] TaskModelDto dto)
 {
     return(_TaskModelService.Update(dto, CurrentUser));
 }
 public TaskModelDto Add([FromBody] TaskModelDto dto)
 {
     return(_TaskModelService.Add(dto, CurrentUser));
 }