public IActionResult ChangeCategory(InputCategoryModel category)
 {
     if (ModelState.IsValid)
     {
         _categoryService.UpdateCategory(category);
     }
     return(RedirectToAction("ChangeCategory"));
 }
        public void UpdateCategory(InputCategoryModel category)
        {
            var categoryFromDb = _db.Categories.Find(category.Id);

            categoryFromDb.Name = category.Name;

            _db.SaveChanges();
        }
        public void AddCategory(InputCategoryModel category)
        {
            var newCategory = new Category
            {
                Id   = category.Id,
                Name = category.Name
            };

            _db.Categories.Add(newCategory);
            _db.SaveChanges();
        }
        public IActionResult ChangeCategory(int id)
        {
            ViewBag.Title = "Breyta flokki";
            var category = _categoryService.GetCategory(id);

            var inputCategory = new InputCategoryModel
            {
                Name = category.Name,
                Id   = category.Id
            };

            return(View(inputCategory));
        }
Example #5
0
 public int CreateCategory(InputCategoryModel categoryModel)
 {
     using (var scope = new TransactionScope())
     {
         var category = new Category
         {
             Name     = categoryModel.Name,
             Language = categoryModel.Language,
             ImageUrl = categoryModel.ImageUrl
         };
         _unitOfWork.CategoryRepository.Add(category);
         _unitOfWork.Save();
         scope.Complete();
         return(category.Id);
     }
 }
Example #6
0
 // POST: api/Category
 /// <summary>
 /// Add new category
 /// </summary>
 /// <param name="categoryModel">new category model</param>
 /// <returns>id of the newly created model</returns>
 public int Post([FromBody] InputCategoryModel categoryModel)
 {
     //categoryModel.Language = CurrentLanguage;
     return(_categoryService.CreateCategory(categoryModel));
 }
Example #7
0
 public void AddCategory(InputCategoryModel category)
 {
     _categoryRepo.AddCategory(category);
 }
Example #8
0
 public void UpdateCategory(InputCategoryModel category)
 {
     _categoryRepo.UpdateCategory(category);
 }