Exemple #1
0
        public async Task <IActionResult> OnPost(int productId)
        {
            Whiskey = await _whiskeyDb.Delete(productId);

            if (Whiskey == null)
            {
                return(RedirectToPage("./NotFound"));
            }
            await _whiskeyDb.Commit();

            return(RedirectToPage("./ListWhiskey"));
        }
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                TempData["Message"] = "Created a new reservation.";
                await _whiskeysDb.Update(Product);

                await _whiskeysDb.Commit();

                return(RedirectToPage("Products/Details",
                                      new { whiskeyId = Product.Id }));
            }
            return(Page());
        }
Exemple #3
0
        public async Task <IActionResult> OnPost(PageViewModels.InputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                RegisteredWhiskeyTypes = _whiskeysDb.GetAllTypes().Result.GetWhiskeyTypesSelectList();
                return(Page());
            }
            else
            {
                if (ImageUpload != null)
                {
                    var directoryPath = Path.Combine(_webHostEnvironment.ContentRootPath,
                                                     "wwwroot",
                                                     "uploads",
                                                     Whiskey.Id.ToString());
                    var filePath = Path.Combine(directoryPath,
                                                Path.GetFileName(ImageUpload.FileName));

                    Directory.CreateDirectory(directoryPath);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        if (ImageUpload.ContentType.ToString().Contains("image"))
                        {
                            ImageUpload.CopyTo(fileStream);
                        }
                    }

                    Whiskey.ImagePath = Path.Combine(@"\uploads",
                                                     Whiskey.Id.ToString(),
                                                     Path.GetFileName(filePath));
                }
                TempData["Message"] = "Added a new Whiskey product";

                //TODO check if this redirect is necessary
                if (inputModel.NewWhiskeyType == null && Int32.Parse(inputModel.productTypeId) == 0)
                {
                    Page();
                }

                Whiskey.WhiskeyType = inputModel.NewWhiskeyType == null
                    ? await _whiskeysDb.GetTypeById(Int32.Parse(inputModel.productTypeId))
                    : await _whiskeysDb.CreateType(inputModel.NewWhiskeyType);

                await _whiskeysDb.Create(Whiskey);

                await _whiskeysDb.Commit();
            }
            return(RedirectToPage("DetailsWhiskey",
                                  new { productId = Whiskey.Id }));
        }
Exemple #4
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                TempData["Message"] = "Created a new whiskey.";
                await _whiskeys.Update(Whiskey);

                await _whiskeys.Commit();

                //BUG: Redirect to details not showing.
                return(RedirectToPage("DetailsWhiskey",
                                      new { productId = Whiskey.Id }));
            }
            //TODO: Repopulate dropdown list values.
            return(Page());
        }