Пример #1
0
        private TaskInfo EditTask(EditTaskDTO task, string authorName, int assigneeId, string priority)
        {
            if (task.Deadline < DateTime.Now)
            {
                throw new DateIsWrongException($"Deadline date \"{task.Deadline}\" cannot be less than current date \"{DateTime.Now}\"");
            }

            PersonDTO authorDTO = mapper.Map <Person, PersonDTO>(db.People.Find(p => p.UserName == authorName).SingleOrDefault());

            if (authorDTO == null)
            {
                throw new PersonNotFoundException($"Author \"{authorName}\" has not found");
            }

            PersonDTO assigneeDTO = mapper.Map <Person, PersonDTO>(db.People.Find(p => p.Id == assigneeId).SingleOrDefault());

            if (assigneeDTO == null)
            {
                throw new PersonNotFoundException($"Assignee \"{assigneeId}\" has not found");
            }

            PriorityDTO priorityDTO = mapper.Map <Priority, PriorityDTO>(db.Priorities.Find(p => p.Name == priority).SingleOrDefault());

            if (priorityDTO == null)
            {
                throw new PriorityNotFoundException($"Priority \"{priority}\" has not known");
            }

            StatusDTO status = mapper.Map <Status, StatusDTO>(db.Statuses.Find(s => (s.Name == "Not Started")).SingleOrDefault());

            if (status == null)
            {
                throw new StatusNotFoundException("Status \"Not Started\" has not found in database");
            }

            var newTask = new TaskInfo
            {
                Name        = task.Name,
                Description = task.Description,
                PriorityId  = priorityDTO.Id,
                AuthorId    = authorDTO.Id,
                AssigneeId  = assigneeDTO.Id,
                StatusId    = status.Id,
                Progress    = 0,
                StartDate   = null,
                FinishDate  = null,
                Deadline    = task.Deadline,
            };

            // For sending email to assignee when task created or updated.
            EmailBody = string.Format(EmailService.BODY_NEW_TASK,
                                      assigneeDTO.FName + " " + assigneeDTO.LName, task.Name, authorDTO.FName + " " + authorDTO.LName);
            EmailSender    = authorDTO.Email;
            EmailRecipient = assigneeDTO.Email;

            return(newTask);
        }
Пример #2
0
        public void CreateTask(EditTaskDTO task, string authorName, int assigneeId, string priority)
        {
            var newTask = EditTask(task, authorName, assigneeId, priority);

            db.Tasks.Create(newTask);
            db.Save();

            emailService.Send(EmailSender, EmailRecipient, EmailService.SUBJECT_NEW_TASK, EmailBody);
        }
Пример #3
0
 public IHttpActionResult Put(EditTaskDTO dto)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _service.Edit(dto);
     return(Ok(""));
 }
Пример #4
0
 public IHttpActionResult UpdateTask(EditTaskDTO task)
 {
     try
     {
         service.UpdateTask(task);
         return(Ok());
     }
     catch (Exception e)
     {
         return(InternalServerError(e));
     }
 }
Пример #5
0
        public void UpdateTask(EditTaskDTO taskInfo)
        {
            var updatedTask = db.Tasks.FirstOrDefault(t => t.TaskId == taskInfo.Id);

            updatedTask.Title       = taskInfo.Title;
            updatedTask.StartDate   = taskInfo.StartDate;
            updatedTask.Reward      = taskInfo.Reward;
            updatedTask.Length      = taskInfo.Length;
            updatedTask.Description = taskInfo.Description;
            updatedTask.City        = taskInfo.City;
            updatedTask.Address     = taskInfo.Address;

            Db.SaveChanges();
        }
Пример #6
0
        public void Edit(EditTaskDTO dto)
        {
            Task task = _c.Tasks.Find(dto.Id);

            if (task == null)
            {
                throw new NullReferenceException();
            }

            task.Name = dto.Name;
            task.End  = dto.End;

            _c.Entry <Task>(task).State = System.Data.Entity.EntityState.Modified;
            _c.SaveChanges();
        }
Пример #7
0
        public void UpdateTask(EditTaskDTO task, int id, string authorName, int assigneeId, string priority)
        {
            TaskInfo taskForEdit = db.Tasks.GetById(id);

            if (taskForEdit != null)
            {
                TaskInfo newTask = EditTask(task, authorName, assigneeId, priority);

                newTask.Id         = taskForEdit.Id;
                newTask.Progress   = taskForEdit.Progress;
                newTask.StartDate  = taskForEdit.StartDate;
                newTask.StatusId   = taskForEdit.StatusId;
                newTask.FinishDate = taskForEdit.FinishDate;

                db.Tasks.Update(taskForEdit.Id, newTask);
                db.Save();

                emailService.Send(EmailSender, EmailRecipient, EmailService.SUBJECT_NEW_TASK, EmailBody);
            }
            else
            {
                throw new TaskNotFoundException($"Current task \"{id}\"has not found");
            }
        }
Пример #8
0
 public void UpdateTask(EditTaskDTO task)
 {
     TaskLogic.UpdateTask(task);
 }