Exemplo n.º 1
0
        public IActionResult OnPost()
        {
            var stream = uploadFile.OpenReadStream();

            var uploadPath = Path.Combine(_hostingEnvironment.WebRootPath, "Images");

            if (Directory.Exists(uploadPath) == false)
            {
                Directory.CreateDirectory(uploadPath);
            }
            var fullPath = Path.Combine(uploadPath, uploadFile.FileName);

            using (var fileStream = new FileStream(fullPath, FileMode.Create))
            {
                stream.CopyTo(fileStream);

                MenuItem.ImagePath = "/Images/" + uploadFile.FileName;
            }

            MenuItem.isUse = true;

            //if (ModelState.IsValid)
            //{
            _menuItemRepository.AddItem(MenuItem);
            _menuItemRepository.Save();

            return(RedirectToPage("General"));
            //}

            //return Page();
        }
Exemplo n.º 2
0
        public ActionResult Post([FromBody] MenuItem item)
        {
            if (ModelState.IsValid)
            {
                _menuItemRepository.AddItem(item);
                _menuItemRepository.Save();

                return(Ok());
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Exemplo n.º 3
0
        private MenuItem Create(ItemViewModel item)
        {
            MenuItem t = new MenuItem
            {
                Name             = item.Name,
                Desc             = item.Desc,
                Price            = item.Price,
                ImageUrl         = item.ImageUrl,
                IsDailySpecial   = item.IsDailySpecial,
                IsVegetarian     = item.IsVegetarian,
                ModuleId         = ActiveModule.ModuleID,
                AddedByUserId    = UserInfo.UserID,
                ModifiedByUserId = UserInfo.UserID,
                DateAdded        = DateTime.UtcNow,
                DateModified     = DateTime.UtcNow
            };

            _repository.AddItem(t);

            return(t);
        }