Example #1
0
        public async Task <ActionResult> Create([Bind(Include = "CategoryID,CategoryName,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                await _category.CreateAsync(category);

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public async Task <ActionResult> CategoryUpsert(Category info)
        {
            if (info.CategoryId > 0)
            {
                Category category = await _category.FindAsync(x => x.CategoryId == info.CategoryId);

                category.Name        = info.Name;
                category.Description = info.Description;
                await _category.UpdateAsync(category);
            }
            else
            {
                Category category = new Category()
                {
                    Name        = info.Name,
                    Description = info.Description
                };
                await _category.CreateAsync(category);
            }
            return(Redirect("/trang-quan-tri/quan-ly-danh-muc"));
        }