Esempio n. 1
0
        public ActionResult CreateProject(ProjectManipulationViewModel newProject)
        {
            var project = new Project()
            {
                Title      = newProject.Title,
                IsArchived = false
            };

            DbContext.Projects.Add(project);
            DbContext.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult EditProject(int?projectId)
        {
            var project = ProjectHelper.GetProjectById(DbContext, (int)projectId);

            if (project is null)
            {
                return(RedirectToAction("Index"));
            }

            var projectViewModel = new ProjectManipulationViewModel()
            {
                Title = project.Title,
                Id    = project.Id
            };

            return(View(projectViewModel));
        }
Esempio n. 3
0
        public ActionResult EditProject(ProjectManipulationViewModel editedProject)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var projectFromDb = ProjectHelper.GetProjectById(DbContext, editedProject.Id);

            if (projectFromDb is null)
            {
                return(RedirectToAction("Index"));
            }

            projectFromDb.Title = editedProject.Title;
            DbContext.SaveChanges();

            return(RedirectToAction("Index"));
        }