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

            return View(category);
        }
Esempio n. 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);
        }
Esempio n. 3
0
 public void EditCategory(Category categoryToEdit)
 {
     db.Entry(categoryToEdit).State = EntityState.Modified;
 }
Esempio n. 4
0
 public void DeleteCategory(Category categoryToDelete)
 {
     db.Categories.Remove(categoryToDelete);
 }
Esempio n. 5
0
 public void CreateCategory(Category categoryToCreate)
 {
     db.Categories.Add(categoryToCreate);
 }