예제 #1
0
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                categoryRepo.CreateCategory(category);
                categoryRepo.Save();
                return RedirectToAction("Index");
            }

            return View(category);
        }
예제 #2
0
        public IHttpActionResult PostCategory(string name)
        {
            if (this.Data.Categories.All().Any(c => c.Name == name))
            {
                return this.BadRequest("Duplicated Category");
            }

            var category = new Category()
           {
               Name = name
           };

            this.Data.Categories.Add(category);
            this.Data.SaveChanges();

            return this.Ok(category);
        }
예제 #3
0
 public void EditCategory(Category categoryToEdit)
 {
     db.Entry(categoryToEdit).State = EntityState.Modified;
 }
예제 #4
0
 public void DeleteCategory(Category categoryToDelete)
 {
     db.Categories.Remove(categoryToDelete);
 }
예제 #5
0
 public void CreateCategory(Category categoryToCreate)
 {
     db.Categories.Add(categoryToCreate);
 }