Exemple #1
0
 public static Model.Stores MapStore(Core.Store store)
 {
     return(new Model.Stores
     {
         StoreId = store.StoreId,
         City = store.City,
         State = store.State
     });
 }
        public ActionResult DrinkCreate(Vending.Models.Admin.DrinkViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var    originalFilename = "";
                    var    extFile          = "";
                    string fileId           = "";
                    if (Request.Files["pic_url"] != null && Request.Files["pic_url"].ContentLength != 0)
                    {
                        var fff = Request.Files["pic_url"];
                        originalFilename = Path.GetFileName(fff.FileName);
                        extFile          = Path.GetExtension(fff.FileName);
                        fileId           = Guid.NewGuid().ToString().Replace("-", "") + extFile;

                        var path = Path.Combine(Server.MapPath("~/Content/drinks/"), fileId);
                        fff.SaveAs(path);
                    }

                    Core.Drink drink = new Core.Drink();
                    model.CopyTo(drink);
                    drink.picture = fileId;
                    drink.Save();
                    // Сохраняем количество
                    Core.Store store = new Core.Store();
                    store.drink_id = drink.id;
                    store.qty      = model.qty;
                    store.Save();

                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                // Стоит сделать редирект на страницу с ошибкой или записать ее куда-нибудь
                return(RedirectToAction("Index"));
            }
        }