Exemplo n.º 1
0
        public async Task <ActionResult> AddImageAsync(HttpPostedFileBase file, int itemid)
        {
            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("~/Content/assets/img/"),
                                               Path.GetFileName(file.FileName));
                    file.SaveAs(path);

                    MenuItemRepository rep = new MenuItemRepository(sqlConnection);
                    MenuItemModel      md  = await rep.GetItemById(itemid);

                    md.Image    = file.FileName;
                    md.Modified = DateTime.UtcNow;
                    await rep.UpdateItem(md);

                    ViewBag.Message = "File uploaded successfully";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }
            return(Redirect("/Menu/Edit/" + itemid.ToString()));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit(long ModelId)
        {
            MenuItemRepository       rep   = new MenuItemRepository(sqlConnection);
            MenuIngredientRepository igrep = new MenuIngredientRepository(sqlConnection);
            EditMenuItemModel        md    = new EditMenuItemModel();

            md.MenuItem = await rep.GetItemById(ModelId);

            md.ItemCatergories = await rep.GetItemCatergories(User.Identity.GetUserId());

            md.AvailableIngredients = await igrep.GetItems(User.Identity.GetUserId());

            md.CurrentIngredients = await rep.GetCurrentItemIngredients(ModelId);

            return(View(md));
        }