public void CreateNewProject(int userId, ProjectData data)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var project = new Project()
                {
                    Name = data.Name,
                    Description = data.Description,
                    Deadline = data.Deadline,
                    Done = data.Done,
                    CreatedDate = DateTime.Now
                };

                context.Project.Add(project);

                context.Role.Add(new Role()
                {
                    ProjectUserId = userId,
                    Type = new ProjectUserManager().GetLeaderId(),
                    Project = project
                });

                context.SaveChanges();
            }
        }
        public void Delete(int statisticsId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var statistics = context.Statistics.SingleOrDefault(s => s.Id == statisticsId);

                if (statistics != null)
                {
                    context.Statistics.Remove(statistics);
                    context.SaveChanges();
                }
            }
        }
        public void TogglePublic(int statisticsId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var statistics = context.Statistics.SingleOrDefault(s => s.Id == statisticsId);

                if (statistics != null)
                {
                    statistics.Public = !statistics.Public;
                    context.SaveChanges();
                }
            }
        }
示例#4
0
        public void AcceptAppliance(int taskId, int userId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var assignment = context.Assignment.FirstOrDefault(
                    a => a.TaskId == taskId && a.ProjectUserId == userId && a.Accepted == false);

                if (assignment != null)
                {
                    assignment.Accepted = true;
                    context.SaveChanges();
                }
            }
        }
        public int AddUserAndReturnId(string userName)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var user = new ProjectUser()
                {
                    UserName = userName
                };

                context.ProjectUser.Add(user);
                context.SaveChanges();

                return user.Id;
            }
        }
示例#6
0
        public void AddComment(CommentData data)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                context.Comment.Add(new Comment()
                {
                    ProjectUserId = data.ProjectUserId,
                    TaskId = data.TaskId,
                    Content = data.Content,
                    Timestamp = data.Timestamp
                });

                context.SaveChanges();
            }
        }
示例#7
0
        public void AcceptStateChange(int taskId, int userId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var change = context.TaskStateChange.FirstOrDefault(
                    a => a.TaskId == taskId && a.ProjectUserId == userId && a.Accepted == false);

                var task = context.Task.First(t => t.Id == taskId);

                if (change != null)
                {
                    change.Accepted = true;
                    task.State = change.TaskState;
                    context.SaveChanges();
                }
            }
        }
        public void AddNewStatistics(StatisticsData data)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                Statistics stat = new Statistics()
                {
                    ProjectId = data.ProjectId,
                    Name = data.Name,
                    CreatedDate = data.CreatedDate,
                    Public = data.Public,
                    Chart = data.ImageContent
                };

                context.Statistics.Add(stat);
                context.SaveChanges();
            }
        }
示例#9
0
        public void AddDeveloperToTask(int userId, int taskId, bool accepted)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int developerId = new ProjectUserManager().GetDeveloperId();
                var assignments = context.Assignment.Where(
                    a => a.TaskId == taskId && a.ProjectUserId == userId);

                if (assignments.Count() == 0)
                {
                    context.Assignment.Add(new Assignment()
                    {
                        ProjectUserId = userId,
                        TaskId = taskId,
                        Accepted = accepted
                    });

                    context.SaveChanges();
                }
            }
        }
        public void AddDeveloperToProject(int userId, int projectId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int developerId = GetDeveloperId();
                var roles = context.Role.Where(
                    r => r.ProjectId == projectId && r.ProjectUserId == userId && r.Type == developerId);

                if (roles.Count() == 0)
                {
                    context.Role.Add(new Role()
                    {
                        ProjectUserId = userId,
                        ProjectId = projectId,
                        Type = developerId
                    });

                    context.SaveChanges();
                }
            }
        }
示例#11
0
        public void AddNewTask(int projectId, TaskData data)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int newId = GetNewStateId();

                context.Task.Add(new Task()
                    {
                        Name = data.Name,
                        Description = data.Description,
                        Priority = data.Priority,
                        MaxDevelopers = data.MaxDevelopers,
                        EstimatedWorkHours = data.EstimatedWorkHours,
                        ProjectId = projectId,
                        State = newId
                    });

                context.SaveChanges();
            }
        }
示例#12
0
        public void DeleteTask(int taskId, int userId, string reason)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int deletedId = GetDeletedStateId();

                var task = context.Task.First(t => t.Id == taskId);
                task.State = deletedId;

                context.TaskStateChange.Add(new TaskStateChange()
                    {
                        ProjectUserId = userId,
                        Timestamp = DateTime.Now,
                        TaskId = taskId,
                        TaskState = deletedId,
                        Accepted = true,
                        Reason = reason != string.Empty ? reason : null
                    });

                context.SaveChanges();
            }
        }
        public void FinishProject(int projectId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var project = context.Project.First(p => p.Id == projectId);

                project.Done = true;

                context.SaveChanges();
            }
        }
示例#14
0
        public bool FinalizeUserApplication(int taskId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int activeId = GetActiveStateId();

                var task = context.Task.First(t => t.Id == taskId);

                var unAcceptedAssignments = context.Assignment.Where(a => a.TaskId == taskId &&
                    a.Accepted == false);

                if (unAcceptedAssignments.Count() == 0)
                {
                    task.State = activeId;
                    context.SaveChanges();
                    return true;
                }

                return false;
            }
        }
        public void RemoveDeveloperFromProject(int userId, int projectId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int developerId = GetDeveloperId();
                var role = context.Role.FirstOrDefault(
                    r => r.ProjectId == projectId && r.ProjectUserId == userId && r.Type == developerId);

                if (role != null)
                    context.Role.Remove(role);

                context.SaveChanges();
            }
        }
示例#16
0
        public void RemoveDeveloperFromTask(int userId, int taskId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int developerId = new ProjectUserManager().GetDeveloperId();
                var assignment = context.Assignment.FirstOrDefault(
                    a => a.TaskId == taskId && a.ProjectUserId == userId);

                if (assignment != null)
                    context.Assignment.Remove(assignment);

                context.SaveChanges();
            }
        }
示例#17
0
        public void RestoreTask(int taskId, int userId, string reason)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int newId = GetNewStateId();
                int activeId = GetActiveStateId();

                var task = context.Task.First(t => t.Id == taskId);

                var workTimes = context.Worktime.Where(w => w.TaskId == taskId);

                //if (workTimes.Count() > 0)
                //    task.State = activeId;
                //else
                    task.State = newId;

                context.TaskStateChange.Add(new TaskStateChange()
                {
                    ProjectUserId = userId,
                    Timestamp = DateTime.Now,
                    TaskId = taskId,
                    TaskState = task.State,
                    Accepted = true,
                    Reason = reason != string.Empty ? reason : null
                });

                context.SaveChanges();
            }
        }
示例#18
0
        public void UnfinishTask(int taskId, int userId, string reason, bool accepted)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                int activeId = GetActiveStateId();

                var task = context.Task.First(t => t.Id == taskId);

                if (accepted)
                    task.State = activeId;

                context.TaskStateChange.Add(new TaskStateChange()
                {
                    ProjectUserId = userId,
                    Timestamp = DateTime.Now,
                    TaskId = taskId,
                    TaskState = activeId,
                    Accepted = accepted,
                    Reason = reason != string.Empty ? reason : null
                });

                context.SaveChanges();
            }
        }
示例#19
0
        public bool AddWorkTime(WorktimeData data)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var relatedWorkTimes = context.Worktime.Where(w => w.TaskId == data.TaskId &&
                    w.ProjectUserId == data.ProjectUserId);
                var overLappingWorkTimes = relatedWorkTimes.Where(w =>
                    (data.StartTime > w.StartTime && data.StartTime < w.EndTime) ||
                    (data.EndTime > w.StartTime && data.EndTime < w.EndTime));

                if (overLappingWorkTimes.Count() == 0)
                {

                    context.Worktime.Add(new Worktime()
                    {
                        ProjectUserId = data.ProjectUserId,
                        TaskId = data.TaskId,
                        StartTime = data.StartTime,
                        EndTime = data.EndTime
                    });

                    context.SaveChanges();
                    return true;
                }

                return false;
            }
        }
示例#20
0
        public void DeclineStateChange(int taskId, int userId)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var change = context.TaskStateChange.FirstOrDefault(
                    a => a.TaskId == taskId && a.ProjectUserId == userId && a.Accepted == false);

                if (change != null)
                {
                    context.TaskStateChange.Remove(change);
                    context.SaveChanges();
                }
            }
        }