public bool UpdateProject(Project instance) { try { Project project = Db.Projects.Find(instance.ProjectId); Type type = instance.GetType(); foreach (var info in type.GetProperties()) { if (info.CanWrite) { var value = info.GetValue(instance); if (value != null) { info.SetValue(project, value, null); } } } Db.SaveChanges(); return true; } catch { return false; } }
public ActionResult Edit(Project project) { ViewBag.CategoryId = new SelectList(Repository.Categories, "CategoryId", "Name", project.CategoryId); if (ModelState.IsValid) { var result = Repository.UpdateProject(project); } return RedirectToAction("Edit", new { projectId = project.ProjectId }); }
public ActionResult Create(Project project) { if (ModelState.IsValid) { db.Projects.Add(project); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", project.CategoryId); return View(project); }
public ActionResult Add() { var project = new Project() { AuthorId = CurrentUser.UserId, EventDate = null, OrganizationDate = null, AddedTime = DateTime.Now, ChangeTime = DateTime.Now }; var result = Repository.CreateProject(project); return RedirectToAction("Edit", new {projectId=project.ProjectId}); }
public bool CreateProject(Project instance) { try { if (instance.ProjectId == 0) { Db.Projects.Add(instance); Db.SaveChanges(); return true; } return false; } catch { return false; } }
public ActionResult Edit(Project project) { if (ModelState.IsValid) { db.Entry(project).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", project.CategoryId); return View(project); }