Exemplo n.º 1
0
        // create category
        public async Task <CategoryViewsModels> Create(CategoryViewsModels addCategory)
        {
            var category = new Category()
            {
                CategoryName = addCategory.CategoryName,
            };

            _context.Categories.Add(category);
            await _context.SaveChangesAsync();

            return(addCategory);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, CategoryViewsModels editCategory)
        {
            if (ModelState.IsValid)
            {
                if (id == editCategory.Id)
                {
                    await _category.EditCategory(id, editCategory);

                    TempData["EditSuccessfuly"] = _localizer.GetLocalizedString("msg_EditSuccessfuly");
                    return(RedirectToAction("Index"));
                }
            }
            ViewData["EditFailure"] = _categoryLocalizer.GetLocalizedString("err_EditFailure");
            return(View());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(CategoryViewsModels category)
        {
            if (ModelState.IsValid)
            {
                var addCategory = await _category.Create(category);

                if (addCategory != null)
                {
                    TempData["AddSuccessfuly"] = _localizer.GetLocalizedString("msg_AddSuccessfuly");
                    return(RedirectToAction("Index"));
                }
            }
            ViewData["AddFailure"] = _categoryLocalizer.GetLocalizedString("err_AddFailure");
            return(View(category));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(CategoryViewsModels editCategory)
        {
            if (ModelState.IsValid)
            {
                var category = await _category.EditCategoryAsync(editCategory);

                if (category)
                {
                    TempData["Successfuly"] = _localizer.GetLocalizedString("msg_EditSuccessfuly").ToString();
                    return(RedirectToAction("Index"));
                }
                TempData["Failure"] = _localizer.GetLocalizedString("err_EditFailure").ToString();
                return(View(editCategory));
            }
            return(View(editCategory));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(CategoryViewsModels category)
        {
            if (ModelState.IsValid)
            {
                var addCategory = await _category.AddCategoryAsync(category);

                if (addCategory)
                {
                    TempData["Successfuly"] = _localizer.GetLocalizedString("msg_AddSuccessfuly").ToString();
                    return(RedirectToAction("Index"));
                }
                ViewData["EditFailure"] = _localizer.GetLocalizedString("err_AddFailure");
                Log.Error("Add category error ");
                return(View(category));
            }
            Log.Error("Add category error ");
            return(View(category));
        }
Exemplo n.º 6
0
        //post edit category
        public async Task <CategoryViewsModels> EditCategory(int?id, CategoryViewsModels editCategory)
        {
            try
            {
                var category = _context.Categories.Find(id);

                category.CategoryName = editCategory.CategoryName;

                _context.Categories.Update(category);
                await _context.SaveChangesAsync();

                return(editCategory);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// post edit category
        /// </summary>
        /// <param name="editCategory">CategoryViewsModels</param>
        /// <returns></returns>
        public async Task <bool> EditCategoryAsync(CategoryViewsModels editCategory)
        {
            try
            {
                var category = await _context.Categories.FindAsync(editCategory.Id);

                category.CategoryName = editCategory.CategoryName;

                _context.Categories.Update(category);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Edit Category Async Error: {0}", e.Message);
                return(false);
            }
        }
Exemplo n.º 8
0
        //post edit category
        public async Task <bool> EditCategoryAsync(CategoryViewsModels editCategory)
        {
            try
            {
                var category = await _context.Categories.FindAsync(editCategory.Id);

                category.CategoryName = editCategory.CategoryName;

                _context.Categories.Update(category);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///  create category service
        /// </summary>
        /// <param name="addCategory">CategoryViewsModels</param>
        /// <returns>true || false</returns>
        public async Task <bool> AddCategoryAsync(CategoryViewsModels addCategory)
        {
            try
            {
                var category = new Category()
                {
                    CategoryName = addCategory.CategoryName
                };
                _context.Categories.Add(category);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Add Category Async Error: {0}", e.Message);

                return(false);
            }
        }
Exemplo n.º 10
0
        // create category
        public async Task <bool> AddCategoryAsync(CategoryViewsModels addCategory)
        {
            try
            {
                var category = new Category()
                {
                    CategoryName = addCategory.CategoryName,
                };

                _context.Categories.Add(category);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }