예제 #1
0
 public void InsertOrUpdate(Category category)
 {
     if (category.Id == default(int)) {
         // New entity
         context.Categories.Add(category);
     } else {
         // Existing entity
         context.Entry(category).State = EntityState.Modified;
     }
 }
예제 #2
0
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                categoryRepository.InsertOrUpdate(category);
                categoryRepository.Save();
                return RedirectToAction("Index", new RouteValueDictionary {{"departmentId", category.DepartmentId}});
            }

            Department dept = departmentRepository.Find(category.DepartmentId);
            category.DepartmentId = dept.Id;
            category.Department = dept;
            PopulateDropDownList();

            return View(category);
        }
예제 #3
0
 private Category LoadCategory(int departmentId)
 {
     Department dept = departmentRepository.Find(departmentId);
     var category = new Category {DepartmentId = dept.Id, Department = dept};
     PopulateDropDownList();
     return category;
 }
예제 #4
0
        public ActionResult Edit(Category category)
        {
            if (ModelState.IsValid)
            {
                categoryRepository.InsertOrUpdate(category);
                categoryRepository.Save();
                return RedirectToAction("Index", new {departmentId = category.DepartmentId});
            }

            PopulateDropDownList();
            return View(category);
        }