Пример #1
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         int backlogItemId = -1;
         using (var entities = new ScrumDB())
         {
             backlogItemId = int.Parse(collection["BacklogItemID"]);
             entities.Tasks.Add(new ScrumTask
             {
                 Name          = collection["Name"],
                 BacklogItemID = backlogItemId,
                 Weight        = int.Parse(collection["Weight"]),
                 Comments      = collection["Comments"]
             });
             entities.SaveChanges();
         }
         if (backlogItemId > -1)
         {
             return(RedirectToAction("Details", "BacklogItem", new { id = backlogItemId }));
         }
         else
         {
             throw new Exception("Backlog item ID is invalid.");
         }
     }
     catch (Exception e)
     {
         return(View()); // TODO: change this
     }
 }
Пример #2
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         using (var entities = new ScrumDB())
         {
             var team = entities.Teams.Find(id);
             if (team == null)
             {
                 throw new InstanceNotFoundException();
             }
             team.Name = collection["Name"];
             entities.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (InstanceNotFoundException exception)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
     }
 }
Пример #3
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                try
                {
                    using (var entities = new ScrumDB())
                    {
                        var bli = entities.BacklogItems.Find(id);
                        bli.Name      = collection["Name"];
                        bli.ProjectID = int.Parse(collection["ProjectID"]);
                        bli.Comments  = collection["Comments"];
                        bli.State     = (ProjectBacklogItem.BacklogItemState) int.Parse(collection["State"]);

                        entities.SaveChanges();
                    }
                    return(RedirectToAction("ProjectBacklog", "Project", new { id = collection["ProjectID"] }));
                }
                catch
                {
                    return(View());
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Пример #4
0
 // GET: BacklogItem/Edit/5
 public ActionResult Edit(int id)
 {
     using (var entities = new ScrumDB())
     {
         return(View(entities.BacklogItems.Find(id)));
     }
 }
Пример #5
0
 // GET: Team
 public ActionResult Index()
 {
     using (var entities = new ScrumDB())
     {
         return(View(entities.Teams.ToList()));
     }
 }
Пример #6
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                using (var entities = new ScrumDB())
                {
                    var item = entities.Tasks.Find(id);
                    if (item == null)
                    {
                        return(RedirectToAction("Details", new { id = id }));
                    }

                    item.Name     = collection["Name"];
                    item.Weight   = int.Parse(collection["Weight"]);
                    item.Comments = collection["Comments"];
                    entities.SaveChanges();

                    return(View("Details", item));
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("Details", new { id = id }));
            }
        }
Пример #7
0
        public ActionResult Index()
        {
            using (var entities = new ScrumDB())
            {
                if (User.IsInRole("Admin"))
                {
                    ViewBag.PageTitle = "All Projects";

                    // if they are an admin show all the projects
                    var projectSummaryList =
                        entities.Projects.Include("BacklogItems")
                        .Include("BacklogItems.Tasks")
                        .Include("Sprints")
                        .ToList();
                    return(View(projectSummaryList));
                }
                else
                {
                    ViewBag.PageTitle = "Your Projects";
                    // check for projects that the user has access to
                    var allowedProjects = ScrumToolAuthorize.AllowedProjects(HttpContext.User.Identity.Name);
                    return(View(allowedProjects));
                }
            }
        }
Пример #8
0
 // GET: Team/Edit/5
 public ActionResult Edit(int id)
 {
     using (var entities = new ScrumDB())
     {
         var team = entities.Teams.Find(id);
         return(View(team));
     }
 }
Пример #9
0
 private bool IsAllowedToAccessProject(string username, int id)
 {
     using (var entities = new ScrumDB())
     {
         var proj = entities.Projects.Find(id);
         return(proj.Users.Any(p => p.UserName == username)); // if the username is in the project's username list
     }
 }
Пример #10
0
 private bool UserInTeam(string username, int teamId)
 {
     using (var entities = new ScrumDB())
     {
         var team = entities.Teams.Find(teamId);
         return(team.Users.Any(p => p.UserName == username)); // if the username is in the teams list
     }
 }
Пример #11
0
        //// GET: ScrumTask
        //public ActionResult Index()
        //{
        //    return View();
        //}

        // GET: ScrumTask/Details/5
        public ActionResult Details(int id)
        {
            using (var entities = new ScrumDB())
            {
                var backlogItem = entities.Tasks.Find(id);
                return(View(backlogItem));
            }
        }
Пример #12
0
        // GET: BacklogItem
        //public ActionResult Index()
        //{
        //    return View();
        //}

        // GET: BacklogItem/Details/5
        public ActionResult Details(int id)
        {
            using (var entities = new ScrumDB())
            {
                var item = entities.BacklogItems.Find(id);
                ViewBag.BacklogItemTaskList = item.Tasks.ToList();
                return(View(item));
            }
        }
Пример #13
0
        // GET: Settings/Admin
        public ActionResult Admin()
        {
            List <AspNetUser> aspNetUserList;

            using (var entities = new ScrumDB())
            {
                aspNetUserList = entities.AspNetUsers.Include("AspNetRoles").ToList();
            }
            return(View(aspNetUserList));
        }
Пример #14
0
 // GET: Settings
 public ActionResult Index()
 {
     using (var entities = new ScrumDB())
     {
         var user = entities.AspNetUsers.FirstOrDefault(u => u.Email == HttpContext.User.Identity.Name);
         if (user != null)
         {
             ViewBag.UserRoles = user.AspNetRoles.ToList();
         }
         return(View());
     }
 }
Пример #15
0
        public ActionResult TeamUsers(string[] users, int teamId)
        {
            try
            {
                using (var db = new ScrumDB())
                {
                    // get all the users
                    var allUsers = db.AspNetUsers.Select(u => u.UserName);

                    // get the team
                    var team = db.Teams.Find(teamId);

                    // get the team's current users
                    var currentTeamUsers     = team.Users;
                    var currentTeamUsersList = currentTeamUsers.Select(u => u.UserName).ToList();


                    // if there are no users in the list we just need to remove them all
                    if (users == null || users.Length == 0)
                    {
                        foreach (var user in currentTeamUsersList)
                        {
                            team.Users.Remove(db.AspNetUsers.FirstOrDefault(u => u.UserName == user));
                        }
                        db.SaveChanges();
                        return(new HttpStatusCodeResult(HttpStatusCode.OK));
                    }

                    // get the users to add and remove
                    var usersToAdd    = users.Except(currentTeamUsersList).ToArray();
                    var usersToRemove = allUsers.Except(users).ToArray();

                    // perform database operations
                    foreach (var item in usersToRemove)
                    {
                        team.Users.Remove(db.AspNetUsers.FirstOrDefault(r => r.UserName == item));
                    }
                    foreach (var item in usersToAdd)
                    {
                        team.Users.Add(db.AspNetUsers.FirstOrDefault(r => r.UserName == item));
                    }

                    // save changes
                    db.SaveChanges();
                }
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
            }
        }
Пример #16
0
 // GET: Team/Delete/5
 public ActionResult Delete(int id)
 {
     using (var entities = new ScrumDB())
     {
         var team = entities.Teams.Find(id);
         if (team == null)
         {
             ViewBag.ErrorMessage = string.Format("Team with ID {0} not found.", id);
             return(RedirectToAction("Index"));
         }
         return(View(team));
     }
 }
Пример #17
0
 public ActionResult BacklogItemTasks(int id)
 {
     using (var entities = new ScrumDB())
     {
         var backlogItem = entities.BacklogItems.Find(id);
         if (backlogItem == null)
         {
             return(HttpNotFound());
         }
         var tasks = backlogItem.Tasks.ToList();
         return(PartialView("_TaskListPartial", tasks));
     }
 }
Пример #18
0
        public static List <Project> AllowedProjects(string username)
        {
            using (var entities = new ScrumDB())
            {
                // lookup valid projects (teams and direct users)
                var projects = entities.Projects.Where(p => p.Users.Any(u => u.UserName == username) ||
                                                       p.Teams.Any(t => t.Users.Any(u => u.UserName == username))).Include("BacklogItems")
                               .Include("BacklogItems.Tasks")
                               .Include("Sprints").ToList();

                return(projects);
            }
        }
Пример #19
0
 // GET: Project/Delete/5
 public ActionResult Delete(int id)
 {
     using (var entities = new ScrumDB())
     {
         var proj = entities.Projects.Find(id);
         if (proj == null)
         {
             ViewBag.ErrorMessage = string.Format("Project id {0} was not found.", id);
             return(RedirectToAction("Index"));
         }
         return(View(proj));
     }
 }
Пример #20
0
        public ActionResult ChangeUserRoles(string[] roles, string username)
        {
            try
            {
                using (var db = new ScrumDB())
                {
                    // get all the user roles
                    var allUserRoles = db.AspNetRoles.Select(r => r.Name).ToList();

                    // get the user
                    var user = db.AspNetUsers.FirstOrDefault(u => u.UserName == username);

                    // get the user's current roles
                    var currentUserRolesCollection = user.AspNetRoles;
                    var currentUserRoles           = currentUserRolesCollection.Select(r => r.Name).ToList();


                    if (roles == null || !roles.Any())
                    {
                        foreach (var role in currentUserRoles)
                        {
                            user.AspNetRoles.Remove(db.AspNetRoles.FirstOrDefault(r => r.Name == role));
                        }
                    }
                    else
                    {
                        // get the roles to add and remove
                        var rolesToAdd    = roles.Except(currentUserRoles).ToArray();
                        var rolesToRemove = allUserRoles.Except(roles).ToArray();

                        // perform database operations
                        foreach (var item in rolesToRemove)
                        {
                            user.AspNetRoles.Remove(db.AspNetRoles.FirstOrDefault(r => r.Name == item));
                        }
                        foreach (var item in rolesToAdd)
                        {
                            user.AspNetRoles.Add(db.AspNetRoles.FirstOrDefault(r => r.Name == item));
                        }
                    }

                    // save changes
                    db.SaveChanges();
                }
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
            }
        }
Пример #21
0
 // GET: Project
 public ActionResult Index()
 {
     using (var entities = new ScrumDB())
     {
         try
         {
             return(View(entities.Projects.ToList()));
         }
         catch (Exception e)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
         }
     }
 }
Пример #22
0
 public ActionResult ProjectBoard(int id)
 {
     using (var entities = new ScrumDB())
     {
         var proj = entities.Projects.Find(id);
         if (proj == null)
         {
             return(View("Index"));
         }
         ViewBag.ProjectID    = proj.ID;
         ViewBag.ProjectTitle = proj.Name;
         var projBacklogList = ProjectBacklogItems(proj);
         return(View(projBacklogList));
     }
 }
Пример #23
0
 public ActionResult ResetPassword(string username)
 {
     using (var entities = new ScrumDB())
     {
         var user = Membership.GetUser(username);
         if (user != null)
         {
             var newPassword = user.ResetPassword();
             return(new HttpStatusCodeResult(HttpStatusCode.OK, newPassword));
         }
         else
         {
             return(new HttpNotFoundResult());
         }
     }
 }
Пример #24
0
 public ActionResult AddUserToTeam(int teamId, string username)
 {
     try
     {
         using (var entities = new ScrumDB())
         {
             var team = entities.Teams.Find(teamId);
             team.Users.Add(entities.AspNetUsers.FirstOrDefault(u => u.UserName == username));
             entities.SaveChanges();
             return(new HttpStatusCodeResult(HttpStatusCode.OK));
         }
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
     }
 }
Пример #25
0
        public async Task <ActionResult> AddThisUserToRole(string roleName)
        {
            using (var entities = new ScrumDB())
            {
                try
                {
                    entities.AspNetUsers.FirstOrDefault(u => u.UserName == HttpContext.User.Identity.Name)
                    .AspNetRoles.Add(entities.AspNetRoles.First(r => r.Name == roleName));
                    await entities.SaveChangesAsync();

                    return(new HttpStatusCodeResult(HttpStatusCode.OK));
                }
                catch (Exception e)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
                }
            }
        }
Пример #26
0
 // GET: Team/Details/5
 public ActionResult Details(int id)
 {
     using (var entities = new ScrumDB())
     {
         try
         {
             var team      = entities.Teams.Find(id);
             var teamUsers = entities.AspNetUsers.Where(u => u.Teams.Any(t => t.ID == id))
                             .Include("AspNetRoles").ToList();
             ViewBag.teamUsers = teamUsers;
             return(View(team));
         }
         catch (Exception e)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
         }
     }
 }
Пример #27
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         using (var entities = new ScrumDB())
         {
             var proj = entities.Projects.Find(id);
             // update the information
             proj.Name = collection["Name"];
             entities.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
     }
 }
Пример #28
0
 public ActionResult StateChange(int backlogItemId, int newState)
 {
     using (var entities = new ScrumDB())
     {
         try
         {
             var item = entities.BacklogItems.Find(backlogItemId);
             item.State    = (ProjectBacklogItem.BacklogItemState)newState;
             item.Priority = null;
             entities.SaveChanges();
         }
         catch (Exception ex)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
         }
     }
     return(new HttpStatusCodeResult(200));
 }
Пример #29
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         using (var entities = new ScrumDB())
         {
             entities.Projects.Add(new Project()
             {
                 Name = collection["Name"]
             });
             entities.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
     }
 }
Пример #30
0
        public ActionResult TeamUserManage(int projectId)
        {
            Project project = null;

            using (var db = new ScrumDB())
            {
                project = db.Projects
                          .Include("Users")
                          .Include("Teams").ToList()
                          .FirstOrDefault(p => p.ID == projectId);

                var projectUsers = db.AspNetUsers.Where(u => u.Projects.Any(p => p.ID == projectId));


                if (project.Teams.Count > 0)
                {
                    var projectTeams = db.Teams.ToList().Except(project.Teams);
                    if (projectTeams.Any())
                    {
                        ViewBag.AllOtherTeams = projectTeams.ToList();
                    }
                }
                else
                {
                    ViewBag.AllOtherTeams = db.Teams.ToList();
                }

                if (projectUsers.Any())
                {
                    var projectUserCollection = db.AspNetUsers.ToList().Except(projectUsers);

                    if (projectUserCollection.Any())
                    {
                        ViewBag.AllOtherUsers = projectUserCollection.ToList();
                    }
                }
                else
                {
                    ViewBag.AllOtherUsers = db.AspNetUsers.ToList();
                }
            }
            return(PartialView("TeamUserManage", project));
        }