Exemplo n.º 1
0
        public bool DeleteById(int id)
        {
            try
            {
                using (var context = new TaskManagerDbContext())
                {
                    var taskModel = context.Tasks.Find(id);
                    if (taskModel == null)
                    {
                        return(false);
                    }

                    var user = context.Users.FirstOrDefault(x => x.TaskId == taskModel.TaskId);
                    if (user != null)
                    {
                        user.TaskId = null;
                        user.Tasks  = null;
                        context.Entry(user).State = EntityState.Modified;
                        context.SaveChanges();
                    }



                    context.Tasks.Remove(taskModel);
                    context.Entry(taskModel).State = EntityState.Deleted;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
        public bool Update(UsersModel userTaskModel)
        {
            try
            {
                using (var context = new TaskManagerDbContext())
                {
                    var taskModel = (from c in context.Users
                                     where c.UsersId == userTaskModel.UserId
                                     select c).FirstOrDefault();
                    if (taskModel == null)
                    {
                        return(false);
                    }
                    taskModel.FirstName  = userTaskModel.FirstName;
                    taskModel.LastName   = userTaskModel.LastName;
                    taskModel.EmployeeId = userTaskModel.EmployeeId;

                    context.Users.Add(taskModel);
                    context.Entry(taskModel).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
Exemplo n.º 3
0
        public bool Update(TaskModel userTaskModel)
        {
            try
            {
                using (var context = new TaskManagerDbContext())
                {
                    var taskModel = (from c in context.Tasks
                                     where c.TaskId == userTaskModel.TaskId
                                     select c).FirstOrDefault();
                    if (taskModel == null)
                    {
                        return(false);
                    }
                    taskModel.TasksDetail = userTaskModel.Task;
                    taskModel.Priority    = userTaskModel.Priority;
                    taskModel.StartDate   = userTaskModel.StartDate;
                    taskModel.StartDate   = userTaskModel.EndDate;
                    taskModel.Status      = userTaskModel.Status;

                    context.Tasks.Add(taskModel);
                    context.Entry(taskModel).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
Exemplo n.º 4
0
        public bool Insert(ProjectModel userModel)
        {
            try
            {
                using (var context = new TaskManagerDbContext())
                {
                    var project = new Project()
                    {
                        Projects = userModel.Projects,
                        Priority = userModel.Priority,
                        // ManagerId = userModel.ManagerId,
                        StartDate = userModel.StartDate,
                        EndDate   = userModel.EndDate,
                        //Users = userModel.
                    };
                    context.Projects.Add(project);
                    context.SaveChanges();

                    var user = context.Users.Find(userModel.ManagerId);
                    user.ProjectId            = project.ProjectId;
                    context.Entry(user).State = EntityState.Modified;
                    context.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public bool Update(ProjectModel userTaskModel)
        {
            try
            {
                using (var context = new TaskManagerDbContext())
                {
                    var projectModel = (from c in context.Projects
                                        where c.ProjectId == userTaskModel.ProjectId
                                        select c).FirstOrDefault();
                    if (projectModel == null)
                    {
                        return(false);
                    }
                    projectModel.Projects  = userTaskModel.Projects;
                    projectModel.Priority  = userTaskModel.Priority;
                    projectModel.ManagerId = userTaskModel.ManagerId;
                    projectModel.StartDate = userTaskModel.StartDate;
                    projectModel.EndDate   = userTaskModel.EndDate;

                    context.Projects.Add(projectModel);
                    context.Entry(projectModel).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
Exemplo n.º 6
0
        public bool Insert(TaskModel userTaskModel)
        {
            try
            {
                using (var context = new TaskManagerDbContext())
                {
                    if (userTaskModel.IsParent)
                    {
                        var parentTask = new Parent()
                        {
                            ParentTaskDetail = userTaskModel.Task
                        };
                        context.ParentTasks.Add(parentTask);
                        context.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        var userTask = new Task()
                        {
                            ParentId    = userTaskModel.ParentTaskId,
                            TasksDetail = userTaskModel.Task,
                            StartDate   = userTaskModel.StartDate,
                            EndDate     = userTaskModel.EndDate,
                            Priority    = userTaskModel.Priority,
                            ProjectId   = userTaskModel.ProjectId,
                            Status      = userTaskModel.Status,
                            // UsersId = userTaskModel.UserId
                        };

                        context.Tasks.Add(userTask);
                        context.SaveChanges();

                        var user = context.Users.Find(userTaskModel.UserId);
                        user.TaskId = userTask.TaskId;
                        context.Entry(user).State = EntityState.Modified;
                        context.SaveChanges();
                        return(true);
                    }
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
 public bool DeleteById(int id)
 {
     try
     {
         using (var context = new TaskManagerDbContext())
         {
             var taskModel = (from c in context.Users
                              where c.UsersId == id
                              select c).FirstOrDefault();
             if (taskModel == null)
             {
                 return(false);
             }
             context.Users.Remove(taskModel);
             context.Entry(taskModel).State = EntityState.Deleted;
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(true);
 }
Exemplo n.º 8
0
        public bool Update(int taskId)
        {
            try
            {
                using (var context = new TaskManagerDbContext())
                {
                    var task = context.Tasks.Find(taskId);
                    if (task == null)
                    {
                        return(false);
                    }
                    task.Status = "Completed";

                    context.Tasks.Add(task);
                    context.Entry(task).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }