Exemplo n.º 1
0
        public async Task <IActionResult> CreatePOST()
        {
            MenuItemVm.MenuItem.SubCategoryId = new Guid(Request.Form["SubCategoryId"].ToString());

            if (!ModelState.IsValid)
            {
                return(View());
            }

            await _service.SaveAsync(MenuItemVm.MenuItem);

            string root  = _hostEnv.WebRootPath;
            var    files = HttpContext.Request.Form.Files;

            var res = _service.AddSaveFoto(files, root, MenuItemVm);

            //var mI = await _service.GetMenuItemByIdAsync(MenuItemVm.MenuItem.Id);

            //if (files[0] != null && files[0].Length > 0)
            //{
            //    var uploads = Path.Combine(root, "images");

            //    var extension = files[0].FileName.Substring(files[0].FileName.LastIndexOf("."),
            //        files[0].FileName.Length - files[0].FileName.LastIndexOf("."));

            //    using (var fs = new FileStream(Path.Combine(uploads, MenuItemVm.MenuItem.Id + extension),
            //        FileMode.Create))
            //    {
            //        files[0].CopyTo(fs);
            //    }

            //    mI.Image = @"\images\" + MenuItemVm.MenuItem.Id + extension;
            //}
            //else
            //{
            //    var uploads = Path.Combine(root, @"images\" + SD.DefaultFoodImage);

            //    System.IO.File.Copy(uploads, root + @"\images\" + MenuItemVm.MenuItem.Id + ".jpg");

            //    mI.Image= @"\images\" + MenuItemVm.MenuItem.Id + ".jpg";
            //}

            return(RedirectToAction(nameof(Index)));
        }