Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Name, ProjectManagerId")] Project project)
        {
            ProjectAssignHelper PA = new ProjectAssignHelper();

            if (ModelState.IsValid)
            {
                int openId = db.ProjectStatuses.FirstOrDefault(p => p.Name == "Open").Id;
                project.ProjectStatusId  = openId;
                project.ProjectStartDate = DateTime.Now;



                var user = db.Users.Find(project.ProjectManagerId);
                project.ProjectManagerName = user.FirstName + " " + user.LastName;
                db.Projects.Add(project);
                db.SaveChanges();

                if (project.ProjectManagerId != null)
                {
                    PA.AddUserToAProject(project.ProjectManagerId, project.Id);
                }


                db.SaveChanges();


                return(RedirectToAction("Index"));
            }

            return(View(project));
        }
Exemplo n.º 2
0
        public ActionResult ProjectAssign(ProjectAssignViewModel model)
        {
            if (ModelState.IsValid)
            {
                var currentUsers = helper.ListUsersOnAProject((int)model.projectId);


                foreach (var user in currentUsers)
                {
                    helper.RemoveUserFromAProject(user.Id, (int)model.projectId);
                }

                if (model.selectedvalue.Any())
                {
                    foreach (var user in model.selectedvalue)
                    {
                        helper.AddUserToAProject(user, (int)model.projectId);
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemplo n.º 3
0
        public ActionResult Create(Project project, List <string> Developers)
        {
            ProjectAssignHelper PA = new ProjectAssignHelper();

            if (ModelState.IsValid)
            {
                int openId = db.ProjectStatuses.FirstOrDefault(p => p.Name == "Open").Id;
                project.ProjectStatusId  = openId;
                project.ProjectStartDate = DateTime.Now;

                var user = db.Users.Find(project.ProjectManagerId);
                project.ProjectManagerName = user.FirstName + " " + user.LastName;
                db.Projects.Add(project);
                db.SaveChanges();

                if (project.ProjectManagerId != null)
                {
                    PA.AddUserToAProject(project.ProjectManagerId, project.Id);
                }

                db.SaveChanges();

                if (Developers != null)
                {
                    foreach (var userId in Developers)
                    {
                        helper.AddUserToAProject(userId, project.Id);
                    }
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            List <ApplicationUser> ProjectManagerId = new List <ApplicationUser>();
            List <ApplicationUser> DeveloperId      = new List <ApplicationUser>();
            UserRolesHelper        uhHelper         = new UserRolesHelper(db);



            var PMs  = uhHelper.UsersInRole("Project Manager1");
            var PMs2 = uhHelper.UsersInRole("Project Manager2");
            var PMs3 = uhHelper.UsersInRole("Project Manager3");
            var AD   = uhHelper.UsersInRole("Admin");
            var AD2  = uhHelper.UsersInRole("Administrator");

            foreach (var PM in PMs)
            {
                ProjectManagerId.Add(PM);
            }
            foreach (var PM in PMs2)
            {
                ProjectManagerId.Add(PM);
            }
            foreach (var PM in PMs3)
            {
                ProjectManagerId.Add(PM);
            }

            var Devs1 = uhHelper.UsersInRole("Developer1");
            var Devs2 = uhHelper.UsersInRole("Developer2");
            var Devs3 = uhHelper.UsersInRole("Developer3");
            var Devs4 = uhHelper.UsersInRole("Developer4");

            foreach (var dev in Devs1)
            {
                DeveloperId.Add(dev);
            }
            foreach (var dev in Devs2)
            {
                DeveloperId.Add(dev);
            }
            foreach (var dev in Devs3)
            {
                DeveloperId.Add(dev);
            }
            foreach (var dev in Devs4)
            {
                DeveloperId.Add(dev);
            }


            ViewBag.Users            = new MultiSelectList(DeveloperId, "Id", "FullName");
            ViewBag.ProjectManagerId = new SelectList(ProjectManagerId, "Id", "FullName");

            var modelErrors = new List <string>();

            foreach (var modelState in ModelState.Values)
            {
                foreach (var modelError in modelState.Errors)
                {
                    modelErrors.Add(modelError.ErrorMessage);
                }
            }

            ViewBag.Errors = modelErrors;

            return(View());
        }