예제 #1
0
 public ActionResult AddCategory(Category model)
 {
     if (ModelState.IsValid)
     {
         repository.SaveCategory(model);
         return RedirectToAction("Home", new { app_culture = Request.RequestContext.RouteData.Values["app_culture"] });
     }
     return View("EditCategory", model);
 }
예제 #2
0
 public void SaveCategory(Category category)
 {
     if (category.CategoryID == 0)
         context.Categories.Add(category);
     else
     {
         Category cat = context.Categories.Single(c => c.CategoryID == category.CategoryID);
         context.Entry(cat).CurrentValues.SetValues(category);
     }
     context.SaveChanges();
     Logger.Info(String.Format("Category with id = {0} and name {0} is saved in database", category.CategoryID, category.CategoryName));
 }
예제 #3
0
 public ActionResult EditCategory(Category model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             HttpPostedFileBase file = Request.Files[0];
             byte[] imageSize = new byte[file.ContentLength];
             file.InputStream.Read(imageSize, 0, (int)file.ContentLength);
             model.Picture = imageSize;
         }
         catch (Exception e)
         {
             ModelState.AddModelError("Picture", AdminStrings.image_error);
         }
         repository.SaveCategory(model);
         return RedirectToAction("Categories", new { app_culture = Request.RequestContext.RouteData.Values["app_culture"] });
     }
     return View(model);
 }
예제 #4
0
 public void DeleteCategory(Category category)
 {
     context.Categories.Remove(category);
     context.SaveChanges();
     Logger.Info(String.Format("Category with id = {0} and name {0} must be removed from database", category.CategoryID, category.CategoryName));
 }