Exemplo n.º 1
0
 public ActionResult Create()
 {
     var model = new App.Web.Areas.Admin.Models.CategoryViewModel
     {
         Category = new App.Models.Category()
     };
     return View(model);
 }
Exemplo n.º 2
0
        public ActionResult Create(App.Web.Areas.Admin.Models.CategoryViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                    throw new Exception();

                var cat = viewModel.Category;

                this.UnitOfWork.CategoryRepository.Insert(cat);
                this.UnitOfWork.Save();

                return RedirectToAction("Index", "Category", new { area = "Admin" });
            }
            catch
            {
                var model = new App.Web.Areas.Admin.Models.CategoryViewModel
                {
                    Category = viewModel.Category,
                };
                return View(model);
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit(App.Web.Areas.Admin.Models.CategoryViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                    throw new Exception();

                var originalCat = this.UnitOfWork.CategoryRepository.GetByID(viewModel.Category.Id);

                if (originalCat == null)
                    throw new Exception();

                originalCat.Title = viewModel.Category.Title;
                originalCat.Description = viewModel.Category.Description;
                originalCat.ModifiedDate = DateTime.Now;

                this.UnitOfWork.CategoryRepository.Update(originalCat);
                this.UnitOfWork.Save();

                return RedirectToAction("Index", "Category", new { area = "Admin" });
            }
            catch
            {
                var model = new App.Web.Areas.Admin.Models.CategoryViewModel
                {
                    Category = viewModel.Category,
                };
                return View(model);
            }
        }
Exemplo n.º 4
0
        // GET: /Admin/Category/Edit/{id}
        public ActionResult Edit(Int64? id)
        {
            try
            {
                var wl = this.UnitOfWork.CategoryRepository.GetByID(id);
                if (wl == null)
                    throw new Exception();

                var model = new App.Web.Areas.Admin.Models.CategoryViewModel
                {
                    Category = this.UnitOfWork.CategoryRepository.GetByID(id),
                };
                return View(model);
            }
            catch
            {
                return RedirectToAction("Index", "Category", new { area = "Admin" });
            }
        }