Exemplo n.º 1
0
        public bool DeleteTask(int id)
        {
            DboTasks task = Context.tasks.Include("users").Where(x => x.taskId == id).FirstOrDefault();


            if (task != null)
            {
                var users = task.users.ToList();
                foreach (DboUsers user in users)
                {
                    //Context.users.Remove(user);
                    task.users.Remove(user);
                }

                Context.tasks.Remove(task);

                //DboUserTtasks ut = Context.usersTasks.FirstOrDefault(x => x.taskId == id);
                //Context.usersTasks.Remove(ut);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public DboTasks CreateNewTask(DboTasks newTask, List <DboUsers> assignedUsers)
        {
            foreach (var user in assignedUsers)
            {
                Context.users.Attach(user);
            }
            newTask.users      = assignedUsers;
            newTask.createdate = DateTime.Now;

            return(Context.tasks.Add(newTask));

            //Context.SaveChanges();
        }
Exemplo n.º 3
0
        public static DboTasks ToDboTask(this TaskDTO taskDTO)
        {
            DboTasks task = new DboTasks();

            if (taskDTO != null)
            {
                task.name        = taskDTO.Name;
                task.description = taskDTO.Description;
                task.statusId    = (int)taskDTO.Status;
                task.duedate     = taskDTO.DueDate;
                //task.AssignedUsersId = task.users != null ? task.users.Select(x => x.userId).ToList() : null;
            }

            return(task);
        }
Exemplo n.º 4
0
        public static TaskDTO ToTaskDTO(this DboTasks task)
        {
            TaskDTO taskDTO = new TaskDTO();

            if (task != null)
            {
                taskDTO.TaskId            = task.taskId;
                taskDTO.Name              = task.name;
                taskDTO.Description       = task.description;
                taskDTO.Status            = (StatusEnum)task.statusId;
                taskDTO.StatusDescription = taskDTO.Status.GetDescription();
                taskDTO.DueDate           = task.duedate;
                taskDTO.AssignedUsersId   = task.users != null?task.users.Select(x => x.userId).ToList() : null;
            }

            return(taskDTO);
        }
Exemplo n.º 5
0
        public DboTasks UpdateTask(DboTasks updateTask, List <DboUsers> assignedUsers)
        {
            foreach (var user in assignedUsers)
            {
                Context.users.Attach(user);
            }
            updateTask.users = assignedUsers;

            DboTasks task = Context.tasks.First(x => x.taskId == updateTask.taskId);

            task.name        = updateTask.name;
            task.description = updateTask.description;
            task.statusId    = updateTask.statusId;
            task.duedate     = updateTask.duedate;
            task.users       = updateTask.users;
            task.updatetime  = DateTime.Now;

            return(task);
        }
Exemplo n.º 6
0
        public IHttpActionResult updateTask(int taskId, TaskDTO taskToCreate)
        {
            using (IUnitOfWork dbTask = new UnitOfWork())
            {
                DboTasks task = dbTask.DataRepo.GetTask(taskId);
                if (task == null)
                {
                    List <Problem> errors = new List <Problem> {
                        new Problem()
                        {
                            Field   = "TaskId",
                            Message = "Invalid Task Id"
                        }
                    };
                    var response = Request.CreateResponse(HttpStatusCode.BadRequest, errors);
                    return(ResponseMessage(response));
                }

                DboTasks updateTask = taskToCreate.ToDboTask();
                updateTask.taskId = taskId;
                List <DboUsers> users         = dbTask.DataRepo.GetAllUsers();
                List <DboUsers> assignedUsers = taskToCreate.AssignedUsersId != null?
                                                users.Where(u => taskToCreate.AssignedUsersId.Contains(u.userId)).ToList()
                                                    : null;

                updateTask = dbTask.DataRepo.UpdateTask(updateTask, assignedUsers);

                List <Problem> validatrionErrors = new List <Problem>();
                if (!updateTask.Validate(validatrionErrors))
                {
                    var response = Request.CreateResponse(HttpStatusCode.BadRequest, validatrionErrors);
                    return(ResponseMessage(response));
                }
                dbTask.SaveChanges();

                return(Ok(updateTask.ToTaskDTO()));
            }
        }
Exemplo n.º 7
0
        public IHttpActionResult CreatTask(TaskDTO taskToCreate)
        {
            using (IUnitOfWork dbTask = new UnitOfWork())
            {
                DboTasks        newTask       = taskToCreate.ToDboTask();
                List <DboUsers> users         = dbTask.DataRepo.GetAllUsers();
                List <DboUsers> assignedUsers = taskToCreate.AssignedUsersId != null?
                                                users.Where(u => taskToCreate.AssignedUsersId.Contains(u.userId)).ToList()
                                                    : null;

                newTask = dbTask.DataRepo.CreateNewTask(newTask, assignedUsers);

                List <Problem> errors = new List <Problem>();
                if (!newTask.Validate(errors))
                {
                    var response = Request.CreateResponse(HttpStatusCode.BadRequest, errors);
                    return(ResponseMessage(response));
                }
                dbTask.SaveChanges();

                return(Ok(newTask.ToTaskDTO()));
            }
        }