public ActionResult AddDish(DishViewModel model, HttpPostedFileBase image)
 {
     if (!ModelState.IsValid)
     {
         ViewBag.Types = DataManager.Dish.GetDishTypes();
         return View(model);
     }
     if (image != null && image.ContentLength > 0)
     {
         // узнаём тип файла
         string fileName = SaveFile(image, "/Uploads/dish");
         model.Image_Url = "/Uploads/dish/" + fileName;
     }
     else
     {
         model.Image_Url = "/Content/images/default-dish.png";
     }
     string idUser = User.Identity.GetUserId();
     // формируем новые данные
     dish item = new dish
     {
         Id_User = idUser,
         Id_Type = model.Id_Type,
         Name = model.Name,
         Description = model.Description,
         ImageUrl = model.Image_Url,
         Price = model.Price,
         PriceWithIngridient = model.PriceWithIngridients,
         Ingridient = model.Ingridients,
         CanTeach = model.CanTeach != null
     };
     //записуем изменения в БД
     DataManager.Dish.AddDish(item);
     return RedirectToAction("index");
 }
Пример #2
0
 public void AddDish(dish item)
 {
     context.dishes.Add(item);
     context.SaveChanges();
 }