コード例 #1
0
        public ActionResult Edit(int id, ProjectEditViewModel projectCreateVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _service.Update(id, projectCreateVM.Title, projectCreateVM.Body, projectCreateVM.ExternalLink, projectCreateVM.Image, projectCreateVM.SelectedItems);

                    return(RedirectToAction(nameof(Index)));
                }
                catch (ModelNotFoundException)
                {
                    return(HttpNotFound());
                }
                catch (ProjectException)
                {
                    foreach (KeyValuePair <string, string> error in _service.Errors)
                    {
                        ModelState.AddModelError(error.Key, error.Value);
                    }
                }
            }

            projectCreateVM.SetCategoriesSelectList(_context.Categories.ToList());
            return(View(projectCreateVM));
        }
コード例 #2
0
        // GET: Projects/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Project project = _context.Projects.Find(id);

            if (project == null)
            {
                return(HttpNotFound());
            }

            ProjectEditViewModel vm = new ProjectEditViewModel();

            vm.Title        = project.Title;
            vm.Body         = project.Body;
            vm.ExternalLink = project.ExternalLink;
            vm.SetCategoriesSelectList(_context.Categories.ToList());

            return(View(vm));
        }