Exemplo n.º 1
0
        public ActionResult Create(TeamCreateViewModel newTeamModel)
        {
            if (UserRepository.IsUserSigned())
            {
                int userId = UserRepository.GetUserId();
                db.Teams.Add(newTeamModel.Team);
                db.SaveChanges();
                TeamRepository.AddUserToTeam(userId, newTeamModel.Team.TeamId, 2);

                if (newTeamModel.ProjectId != 0)
                {
                    var existProject = db.Projects.FirstOrDefault(x => x.ProjectId == newTeamModel.ProjectId);
                    existProject.TeamId = newTeamModel.Team.TeamId;
                    db.SaveChanges();
                }

                if (newTeamModel.from == ViewEnum.HomeIndex)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else if (newTeamModel.from == ViewEnum.ProjectCreate)
                {
                    return(RedirectToAction("Create", "Project"));
                }
                else if (newTeamModel.from == ViewEnum.ProjectEdit)
                {
                    return(RedirectToAction("Edit", "Project", new { id = newTeamModel.ProjectId }));
                }

                return(RedirectToAction("Index", "Team", new { id = userId }));
            }

            return(RedirectToAction("Login", "User"));
        }
Exemplo n.º 2
0
        //test et
        public static bool DeleteTeam(int teamId)
        {
            using (var db = new ScrumApplicationDbContext())
            {
                var existTeam = new Team();
                existTeam = db.Teams.FirstOrDefault(x => x.TeamId == teamId);
                var teamProjects = new List <Project>();
                teamProjects = existTeam.Projects.ToList();
                if (teamProjects.Count != 0)
                {
                    foreach (var p in teamProjects)
                    {
                        if (p.DayCount > 0)
                        {
                            return(false);
                        }
                        else
                        {
                            teamProjects.Remove(p);
                        }
                    }
                }
                else if (teamProjects.Count != 0)
                {
                    db.Teams.Remove(existTeam);
                    db.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 3
0
        public ActionResult Account(AccountViewModel newModel)
        {
            var existUser = db.Users.FirstOrDefault(x => x.UserId == newModel.User.UserId);

            if (newModel.CurrentPassword != null && newModel.NewPassword != null && newModel.ConfirmNewPassword != null)
            {
                if (newModel.CurrentPassword == existUser.Password)
                {
                    if (newModel.NewPassword == newModel.ConfirmNewPassword)
                    {
                        existUser.Password = newModel.NewPassword;
                        db.SaveChanges();
                    }
                    else
                    {
                        return(Content("You entered new password and confirm new password different."));
                    }
                }
                else
                {
                    return(Content("You entered wrong current password."));
                }
            }
            return(RedirectToAction("Account"));
        }
Exemplo n.º 4
0
        public ActionResult Register(UserRegisterViewModel newUser)
        {
            using (var db = new ScrumApplicationDbContext())
            {
                if (db.Users.FirstOrDefault(x => x.Mail == newUser.User.Mail) == null)
                {
                    if (newUser.ConfirmPassword == newUser.User.Password)
                    {
                        var _newUser = new User {
                            FirstName = newUser.User.FirstName,
                            LastName  = newUser.User.LastName,
                            Name      = newUser.User.FirstName + " " + newUser.User.LastName.Substring(0, 1) + ".",
                            Mail      = newUser.User.Mail,
                            Password  = newUser.User.Password
                        };

                        db.Users.Add(_newUser);
                        db.SaveChanges();

                        FormsAuthentication.SetAuthCookie(newUser.User.Mail, true);
                        UserRepository.UpdateUserCookie(newUser.User.UserId);

                        return(RedirectToAction("Index", "Team", new { id = UserRepository.GetUserId() }));
                    }
                }
            }
            return(View(newUser));
        }
Exemplo n.º 5
0
 public static bool CompleteBacklog(int backlogId, int?memberId)
 {
     using (var db = new ScrumApplicationDbContext())
     {
         var existTask = new ProductBacklog();
         existTask = db.ProductBacklogs.FirstOrDefault(x => x.ProductBacklogId == backlogId);
         if (!memberId.HasValue)
         {
             memberId = TeamRepository.GetUserMemberIdFromProjectId(existTask.ProjectId);
         }
         var existMember = db.Members.FirstOrDefault(x => x.MemberId == memberId);
         if (existMember != null)
         {
             if (ProjectRepository.IsUserAssigned(backlogId, existMember.MemberId) == 1)
             {
                 if (existTask.BacklogStatus < Status.Completed)
                 {
                     existTask.BacklogStatus = Status.Completed;
                 }
                 existTask.Done          = true;
                 existMember.TotalPoint += existTask.StoryPoint;
                 db.SaveChanges();
                 ActivityRepository.ActivityCreator
                     ("completed " + existTask.Name, existTask.ProjectId, existTask.ProductBacklogId);
                 return(true);
             }
         }
         return(false);
     }
 }
Exemplo n.º 6
0
        public static bool AddUserToTeam(int userId, int teamId, int roleCode)
        {
            using (var db = new ScrumApplicationDbContext())
            {
                var existTeam = new Team();
                existTeam = db.Teams.FirstOrDefault(x => x.TeamId == teamId);
                bool isMemberAdded = false;
                if (existTeam != null)
                {
                    foreach (var member in existTeam.Members.ToList())
                    {
                        if (member.UserId == userId)
                        {
                            isMemberAdded = true;
                            break;
                        }
                    }
                    if (!isMemberAdded)
                    {
                        var newMember = new Member();
                        var existUser = db.Users.FirstOrDefault(x => x.UserId == userId);
                        newMember.TeamId   = teamId;
                        newMember.UserId   = userId;
                        newMember.Name     = existUser.Name;
                        newMember.Mail     = existUser.Mail;
                        newMember.RoleCode = roleCode;
                        existTeam.Members.Add(newMember);
                        db.SaveChanges();
                        if (roleCode == 2)
                        {
                            var newManager = new Manager();
                            newManager.UserId   = existUser.UserId;
                            newManager.MemberId = newMember.MemberId;
                            newManager.Name     = existUser.Name;
                            newManager.Mail     = existUser.Mail;
                            db.Managers.Add(newManager);
                            db.SaveChanges();
                            existTeam.ManagerId = newManager.ManagerId;
                            db.SaveChanges();
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 7
0
 public static void AddProjectToTeam(int projectId, int teamId)
 {
     using (var db = new ScrumApplicationDbContext())
     {
         var existProject = db.Projects.FirstOrDefault(x => x.ProjectId == projectId);
         var existTeam    = db.Teams.FirstOrDefault(x => x.TeamId == teamId);
         existTeam.Projects.Add(existProject);
         db.SaveChanges();
     }
 }
Exemplo n.º 8
0
        public static void AddTeam(string name)
        {
            var _newTeam = new Team();

            _newTeam.Name = name;

            using (var db = new ScrumApplicationDbContext())
            {
                db.Teams.Add(_newTeam);
                db.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public void AddEpic(string name, int projectId)
        {
            var _newEpic = new Epic();

            _newEpic.Name      = name;
            _newEpic.ProjectId = projectId;

            using (var db = new ScrumApplicationDbContext())
            {
                db.Epics.Add(_newEpic);
                db.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public static void AddUser(string name, string email, string password)
        {
            var _newUser = new User();

            _newUser.Name     = name;
            _newUser.Mail     = email;
            _newUser.Password = password;
            using (var db = new ScrumApplicationDbContext())
            {
                db.Users.Add(_newUser);
                db.SaveChanges();
            }
        }
Exemplo n.º 11
0
        public static void AddProject(string name)
        {
            var _newProject = new Project();

            _newProject.Name = name;

            using (var db = new ScrumApplicationDbContext())
            {
                db.Projects.Add(_newProject);
                db.SaveChanges();
                ActivityRepository.ActivityCreator
                    ("created" + _newProject.Name, _newProject.ProjectId, null);
            }
        }
        public static void AddProductBacklog(int projectId, string name)
        {
            var newTask = new ProductBacklog();

            newTask.Name      = name;
            newTask.ProjectId = projectId;
            using (var db = new ScrumApplicationDbContext())
            {
                db.ProductBacklogs.Add(newTask);
                db.SaveChanges();
            }
            ActivityRepository.ActivityCreator
                ("added " + newTask.Name + " to the project.", newTask.ProjectId, newTask.ProductBacklogId);
        }
Exemplo n.º 13
0
 public static bool ChangeManager(int memberId, int teamId)
 {
     using (var db = new ScrumApplicationDbContext())
     {
         var existTeam = db.Teams.FirstOrDefault(x => x.TeamId == teamId);
         //member that will be new manager
         var existMember = db.Members.FirstOrDefault(x => x.MemberId == memberId);
         //manager that will be deleted
         var existManager = db.Managers.FirstOrDefault(x => x.ManagerId == existTeam.ManagerId);
         //member that role code will change to 3
         var _existMemberManager = db.Members.FirstOrDefault(x => x.MemberId == existManager.MemberId);
         if (existTeam != null && existMember != null && existTeam.TeamId == existMember.TeamId &&
             existManager != null && _existMemberManager != null)
         {
             //exist manager removed because every team can have one manager
             //and manager have one team
             db.Managers.Remove(existManager);
             //member that will be manager role code updated
             existMember.RoleCode = 2;
             //member that was manager role code updated
             _existMemberManager.RoleCode = 3;
             var newManager = new Manager();
             newManager.UserId   = existMember.UserId;
             newManager.MemberId = existMember.MemberId;
             newManager.Mail     = existMember.Mail;
             newManager.Name     = existMember.Name;
             db.Managers.Add(newManager);
             db.SaveChanges();
             existTeam.ManagerId = newManager.ManagerId;
             existTeam.Manager   = newManager;
             db.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Exemplo n.º 14
0
        public static bool RemoveMemberFromTeam(int memberId)
        {
            using (var db = new ScrumApplicationDbContext())
            {
                var existMember = db.Members.FirstOrDefault(x => x.MemberId == memberId);
                var existTeam   = db.Teams.FirstOrDefault(x => x.TeamId == existMember.TeamId);
                if (existMember != null && existTeam != null)
                {
                    existTeam.Members.Remove(existMember);
                    db.Members.Remove(existMember);
                    db.SaveChanges();

                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 15
0
 public static void ActivityCreator(string ActivityString, int projectId, int?backlogId)
 {
     using (var db = new ScrumApplicationDbContext())
     {
         var memberId    = TeamRepository.GetUserMemberIdFromProjectId(projectId);
         var existMember = db.Members.FirstOrDefault(x => x.MemberId == memberId);
         var newActivity = new Activity();
         newActivity.MemberId  = memberId;
         newActivity.ProjectId = projectId;
         if (backlogId.HasValue)
         {
             newActivity.BacklogId = backlogId;
         }
         newActivity.ActivityDescription =
             existMember.Name + " " + ActivityString;
         //" at time: " + DateTime.Now.Minute + "." + DateTime.Now.Hour + " - " + DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year
         db.Activities.Add(newActivity);
         db.SaveChanges();
     }
 }
Exemplo n.º 16
0
 public static bool UnAssignUser(int backlogId, int memberId)
 {
     using (var db = new ScrumApplicationDbContext())
     {
         if (IsUserAssigned(backlogId, memberId) == 1)
         {
             var existBTM = db.BacklogToMembers.FirstOrDefault(x => x.MemberId == memberId && x.ProductBacklogId == backlogId);
             if (existBTM != null)
             {
                 db.BacklogToMembers.Remove(existBTM);
                 db.SaveChanges();
                 var existBacklog = db.ProductBacklogs.FirstOrDefault(x => x.ProductBacklogId == backlogId);
                 ActivityRepository.ActivityCreator
                     ("unassigned " + existBTM.MemberName + " from " + existBacklog.Name,
                     existBacklog.ProjectId, existBacklog.ProductBacklogId);
                 return(true);
             }
         }
         return(false);
     }
 }
Exemplo n.º 17
0
        public ActionResult Create(ProjectEditViewModel existProjectModel)
        {
            if (UserRepository.IsUserSigned() && TeamRepository.IsTeamManager(existProjectModel.Project.TeamId ?? default(int)))
            {
                //Define project informations
                var newProject = new Project();
                newProject = existProjectModel.Project;
                if (existProjectModel.Project.EndDate <= existProjectModel.Project.CreatedDate)
                {
                    return(Content("Please enter an upward EndDate from today's date."));
                }
                db.Projects.Add(newProject);
                db.SaveChanges();

                ActivityRepository.ActivityCreator
                    ("created " + newProject.Name + " project.", newProject.ProjectId, null);

                return(RedirectToAction("Index", "Project", new { id = existProjectModel.Project.TeamId }));
            }

            return(RedirectToAction("Login", "User"));

            //if (UserRepository.IsUserSigned())
            //{
            //    var existTeam = new Team();
            //    newProject.EndDate = newProject.CreatedDate.AddDays(newProject.DayCount);
            //    db.Projects.Add(newProject);
            //    db.SaveChanges();
            //    ActivityRepository.ActivityCreator
            //        ("created " + newProject.Name + " project.", newProject.ProjectId, null);
            //    return RedirectToAction("Index", "Project", new { id = newProject.TeamId });
            //}

            //return RedirectToAction("Login", "User");
        }