Ejemplo n.º 1
0
        public async Task <IActionResult> EditCategory(ViewModels.PM.Category.EditCategoryViewModel editcategory)
        {
            string          ImagePath       = null;
            ImageErrorModel imageErrorModel = new ImageErrorModel();

            if (editcategory.DefaultImage == null)
            {
                ImagePath = editcategory.OldImage;
            }
            else
            {
                ImagePath = UploadImage(editcategory.DefaultImage, ref imageErrorModel);
            }
            if (ModelState.IsValid)
            {
                Category objcategory = await this.CategoryBLL.Find(editcategory.ID);

                objcategory.Description  = editcategory.Description;
                objcategory.Name         = editcategory.Name;
                objcategory.DefaultImage = ImagePath;
                await CategoryBLL.Update(objcategory);

                return(RedirectToAction("Index"));
            }
            return(View(editcategory));
        }
        public IActionResult UpdateCategory(CategoryVM categoryVM, int id)
        {
            User     currentAdmin = HttpContext.Session.Get <User>("currentUser");
            Category category     = categoryBLL.Get(id).Data;

            try
            {
                if (ModelState.IsValid)
                {
                    category.CategoryName = categoryVM.CategoryName;
                    category.Description  = categoryVM.Overview;

                    if (category != null)
                    {
                        try
                        {
                            categoryBLL.Update(category);
                            this._logger.LogInformation($"AdminID : {currentAdmin.ID} is updated CategoryID : {category.ID}");
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                        ViewBag.IsSuccess = true;
                    }
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                ViewBag.IsSuccess = false;
            }
            return(View("Index"));
        }