public async Task <IActionResult> Edit(int?id, HotMenu hotMenu)
        {
            HotMenu hotMenuDb = await _context.HotMenus.FindAsync(id);

            if (!ModelState.IsValid)
            {
                return(View(hotMenu));
            }
            if (hotMenu.Photo != null)
            {
                if (hotMenu.Photo.ContentType.Contains("image/"))
                {
                    string path = _env.WebRootPath + @"\image\" + hotMenuDb.Image;
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }

                    hotMenuDb.Image = await hotMenu.Photo.SaveFileAsync(_env.WebRootPath);
                }
                else
                {
                    ModelState.AddModelError("Photo", "Image is not valid!");
                    return(View(hotMenu));
                }
            }

            hotMenuDb.Name        = hotMenu.Name;
            hotMenuDb.Price       = hotMenu.Price;
            hotMenuDb.Ingredients = hotMenu.Ingredients;

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> DeletePost(int?id)
        {
            HotMenu hotMenu = await _context.HotMenus.FindAsync(id);

            if (id == null)
            {
                return(NotFound());
            }
            if (hotMenu == null)
            {
                return(NotFound());
            }
            string path = _env.WebRootPath + @"\image\" + hotMenu.Image;

            if (_context.HotMenus.ToList().Count > 1)
            {
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                _context.HotMenus.Remove(hotMenu);
                await _context.SaveChangesAsync();
            }
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            HotMenu hotMenu = await _context.HotMenus.FindAsync(id);

            if (id == null)
            {
                return(NotFound());
            }
            if (hotMenu == null)
            {
                return(NotFound());
            }
            return(View(hotMenu));
        }
        public async Task <IActionResult> Create(HotMenu hotMenu)
        {
            if (!ModelState.IsValid)
            {
                return(View(hotMenu));
            }
            if (hotMenu.Photo == null)
            {
                ModelState.AddModelError("Photo", "Please select any image!");
                return(View(hotMenu));
            }
            if (!hotMenu.Photo.ContentType.Contains("image/"))
            {
                ModelState.AddModelError("Photo", "Image is not valid!");
                return(View(hotMenu));
            }
            hotMenu.Image = await hotMenu.Photo.SaveFileAsync(_env.WebRootPath);

            await _context.HotMenus.AddAsync(hotMenu);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     HotMenu.DataSource = ConnSql.Re("select top 5 menuid,COUNT(*) lysl,name=(select name from bbs_menu where id=menuid ) from bbs_ly group by menuid order by 2 desc").DefaultView;
     HotMenu.DataBind();
 }