Example #1
0
        public IActionResult Create(WhiskeyEditModel model)
        {
            if (ModelState.IsValid)
            {
                var newWhiskey = new Whiskey();
                newWhiskey.Name = model.Name;
                newWhiskey.Type = model.Type;

                newWhiskey = _whiskeyData.Add(newWhiskey);

                return(RedirectToAction("Details", new { Id = newWhiskey.Id }));
            }
            else
            {
                return(View());
            }
        }
        public IActionResult OnPost(IFormFile photo)
        {
            var path   = Path.Combine(IWebHostEnvironment.WebRootPath, "Images", photo.FileName);
            var stream = new FileStream(path, FileMode.Create);

            photo.CopyToAsync(stream);
            FileName          = photo.FileName;
            Whiskey.Imagedata = photo.FileName;

            if (!ModelState.IsValid)
            {
                Kinds     = htmlHelper.GetEnumSelectList <Kind>();
                Locations = whiskeyData.GetLocations();

                return(Page());
            }

            Whiskey.Area = whiskeyData.GetLocations().FirstOrDefault(a => a.Id == AreaId);
            whiskeyData.Add(Whiskey);
            whiskeyData.Commit();
            return(RedirectToPage("./Index"));
        }
Example #3
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                WhiskeyTypes  = htmlHelper.GetEnumSelectList <WhiskeyType>();
                WhiskeyBrands = htmlHelper.GetEnumSelectList <WhiskeyBrand>();
                WhiskeyArea   = htmlHelper.GetEnumSelectList <WhiskeyArea>();

                return(Page());
            }

            if (Whiskey.Id > 0)
            {
                whiskeyData.Update(Whiskey);
            }
            else
            {
                whiskeyData.Add(Whiskey);
            }
            whiskeyData.Commit();
            TempData["Message"] = "Whiskey saved!";
            return(RedirectToPage("./Detail", new { whiskeyId = Whiskey.Id }));
        }