public async Task<IActionResult> Add()
 {
     var model = new CategoryViewModel();
     ViewBag.Title = "Add";
     await SetViewBagCategories();
     return View(model);
 }
        public async Task<IActionResult> Add(CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.Slug = model.Slug.ToSlug(); // Remove any special chars etc.
                var newModel = Mapper.Map(model, new Category(), m => new { m.Name, m.Slug, m.ParentCategoryId });

                newModel.CreatedOn = DateTime.Now;
                newModel.CreatedBy = AppSession.AppUserId;

                Db.Categories.Add(newModel);
                await Db.SaveChangesAsync();
                return RedirectToAction("Index");
            }
            //TempData.Danger("Category was not saved! Please check errors.");

            ViewBag.Title = "Add";
            await SetViewBagCategories();
            return View(model);
        }
        public async Task<IActionResult> Delete(CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Can we just update DB without fetching first, need ideas, also concurrency check needs to be done
                var dbModel = await Db.Categories.SingleOrDefaultAsync(d => d.Id == model.Id);
                if (dbModel == null) return HttpNotFound();

                // Need to fix RowStamp check
                //Db.Entry(dbModel).OriginalValues["RowStamp"] = model.RowStamp;
                Db.Categories.Remove(dbModel);
                await Db.SaveChangesAsync();

                //TempData.Success("Category was successfully deleted!");
                return RedirectToAction("Index");
            }
            //TempData.Danger("Category was not deleted! Please check errors.");

            ViewBag.Title = "Delete";
            return View(model);
        }
        public async Task<IActionResult> Edit(CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Can we just update DB without fetching first, need ideas, also concurrency check needs to be done
                var dbModel = await Db.Categories.FirstAsync(c => c.Id == model.Id);
                model.Slug = model.Slug.ToSlug(); // Remove any special chars etc.
                Mapper.Map(model, dbModel, c => new { c.Name, c.Slug, c.ParentCategoryId });

                dbModel.ModifiedOn = DateTime.Now;
                dbModel.ModifiedBy = AppSession.AppUserId;

                // Need to fix RowStamp check
                //Db.Entry(dbModel).OriginalValues["RowStamp"] = model.RowStamp;
                Db.Update(dbModel);
                await Db.SaveChangesAsync();

                //TempData.Success("Category was successfully saved!");
                return RedirectToAction("Index");
            }
            //TempData.Danger("Category was not saved! Please check errors.");

            ViewBag.Title = "Edit";
            await SetViewBagCategories();
            return View("Add", model);
        }