Ejemplo n.º 1
0
        public ActionResult AddProject(AddEditProjectsViewModel formData)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var userId = User.Identity.GetUserId();

            var project = new Project();

            project.Name = formData.Name;

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

            return(RedirectToAction(nameof(ProjectsController.IndexAllProjects)));
        }
Ejemplo n.º 2
0
        public ActionResult EditProject(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(ProjectsController.IndexAllProjects)));
            }

            var project = Context.Projects.FirstOrDefault(p => p.Id == id.Value);

            if (project == null)
            {
                return(RedirectToAction(nameof(ProjectsController.IndexAllProjects)));
            }

            var model = new AddEditProjectsViewModel();

            model.Name = project.Name;


            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult EditProject(int?id, AddEditProjectsViewModel model)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction(nameof(ProjectsController.IndexAllProjects)));
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }

            var project = Context.Projects.FirstOrDefault(p => p.Id == id.Value);

            project.Name        = model.Name;
            project.DateUpdated = DateTime.Now;

            Context.SaveChanges();

            return(RedirectToAction(nameof(ProjectsController.IndexAllProjects)));
        }