Пример #1
0
        public ActionResult SetState(int id, int ProjectStateID)
        {
            if (Session["EmployeeID"] == null)
            {
                Session["PleaseLogin"] = true;
                return(RedirectToAction("", "Home"));
            }
            var permutil = new PermissionUtil();

            if (permutil.IsAdministrator((int)Session["JobPosition"]))
            {
                var projToEdit = ctx.Projects.Find(id);
                if (projToEdit == null)
                {
                    return(HttpNotFound("Projekt o podanym ID nie istnieje!"));
                }

                projToEdit.LastEditDate   = DateTime.Now;
                projToEdit.LastEditedBy   = (int)Session["EmployeeID"];
                projToEdit.ProjectStateID = ProjectStateID;

                if (ProjectStateID == 3)
                {
                    projToEdit.Finish = DateTime.Now;
                }

                ctx.Entry(projToEdit).State = EntityState.Modified;
                ctx.SaveChanges();

                return(RedirectToAction("Overview", "Project"));
            }
            return(RedirectToAction("Overview", "Project"));
        }
Пример #2
0
        public ActionResult Edit([Bind(Include = "ProjectID, Name, SuperiorID, Start, Finish")] Projects project)
        {
            if (Session["EmployeeID"] == null)
            {
                Session["PleaseLogin"] = true;
                return(RedirectToAction("", "Home"));
            }
            var permutil = new PermissionUtil();

            if (permutil.IsAdministrator((int)Session["JobPosition"]))
            {
                var projToEdit = ctx.Projects.Find(project.ProjectID);
                if (projToEdit == null)
                {
                    return(HttpNotFound("Projekt o podanym ID nie istnieje!"));
                }

                projToEdit.Name       = project.Name;
                projToEdit.SuperiorID = project.SuperiorID;
                projToEdit.Start      = project.Start;
                projToEdit.Finish     = project.Finish;

                if (project.Finish != null && project.Start > project.Finish)
                {
                    ModelState.AddModelError("Start", "Data rozpoczęcia jest późniejsza niż data zakończenia projektu.");
                    PopulateSuperiorsList();
                    return(View(projToEdit));
                }

                ctx.Entry(projToEdit).State = EntityState.Modified;
                ctx.SaveChanges();
                return(RedirectToAction("Overview", "Project"));
            }
            return(RedirectToAction("Overview", "Project"));
        }
Пример #3
0
        private void CheckUserPermission()
        {
            PermissionUtil perm = new PermissionUtil();

            if (!perm.IsAdministrator((int)Session["JobPosition"]))
            {
                throw new UnauthorizedAccessException("Nie masz wystarczających uprawnień do oglądania tej witryny.");
            }
        }
Пример #4
0
        public ActionResult New()
        {
            if (Session["EmployeeID"] == null)
            {
                Session["PleaseLogin"] = true;
                return(RedirectToAction("", "Home"));
            }
            var permutil = new PermissionUtil();

            if (permutil.IsAdministrator((int)Session["JobPosition"]))
            {
                PopulateSuperiorsList();
                return(View());
            }
            return(RedirectToAction("Overview", "Project"));
        }
Пример #5
0
        public ActionResult New([Bind(Include = "Name, SuperiorID, Start, Finish, ProjectMembers")] AddProjectViewModel project)
        {
            if (Session["EmployeeID"] == null)
            {
                Session["PleaseLogin"] = true;
                return(RedirectToAction("", "Home"));
            }
            var permutil = new PermissionUtil();

            if (permutil.IsAdministrator((int)Session["JobPosition"]))
            {
                if (project.Finish != null && project.Start > project.Finish)
                {
                    ModelState.AddModelError("Start", "Data rozpoczęcia jest późniejsza niż data zakończenia projektu.");
                    PopulateSuperiorsList();
                    return(View());
                }

                var projectToAdd = new Projects();
                projectToAdd.Name           = project.Name;
                projectToAdd.SuperiorID     = project.SuperiorID;
                projectToAdd.Start          = project.Start;
                projectToAdd.Finish         = project.Finish;
                projectToAdd.CreatedBy      = (int)Session["EmployeeID"];
                projectToAdd.CreationDate   = DateTime.Now;
                projectToAdd.ProjectStateID = 1; // TODO: Change this magic value
                ctx.Projects.Add(projectToAdd);
                ctx.SaveChanges();

                foreach (var emplID in project.ProjectMembers)
                {
                    var pm = new ProjectMembers()
                    {
                        ProjectID  = projectToAdd.ProjectID,
                        EmployeeID = emplID
                    };

                    ctx.ProjectMembers.Add(pm);
                }
                ctx.SaveChanges();
                return(RedirectToAction("Overview", "Project"));
            }
            return(RedirectToAction("Overview", "Project"));
        }
Пример #6
0
        public ActionResult Delete(int id)
        {
            if (Session["EmployeeID"] == null)
            {
                Session["PleaseLogin"] = true;
                return(RedirectToAction("", "Home"));
            }
            var permutil = new PermissionUtil();

            if (permutil.IsAdministrator((int)Session["JobPosition"]))
            {
                Projects proj = new Projects {
                    ProjectID = id
                };
                ctx.Projects.Attach(proj);
                ctx.Projects.Remove(proj);
                ctx.SaveChanges();
                return(RedirectToAction("Overview", "Project"));
            }
            return(RedirectToAction("Overview", "Project"));
        }
Пример #7
0
        public ActionResult Edit(int id)
        {
            if (Session["EmployeeID"] == null)
            {
                Session["PleaseLogin"] = true;
                return(RedirectToAction("", "Home"));
            }
            var permutil = new PermissionUtil();

            if (permutil.IsAdministrator((int)Session["JobPosition"]))
            {
                var proj = ctx.Projects.Find(id);
                if (proj == null)
                {
                    return(HttpNotFound("Projekt o podanym ID nie istnieje!"));
                }
                PopulateProjectStatesList(proj.ProjectStateID.ToString());
                PopulateSuperiorsList(proj.SuperiorID.ToString());
                return(View(proj));
            }
            return(RedirectToAction("Overview", "Project"));
        }