예제 #1
0
        public async Task <IActionResult> Delete(string id)
        {
            var itemFromDb = await this.itemService.GetById(id);

            var auctionHouses = await auctionHouseService.GetAllAuctionHouses().ToListAsync();

            var viewModel = new ItemDeleteViewModel
            {
                Name            = itemFromDb.Name,
                StartingPrice   = itemFromDb.StartingPrice,
                BuyOutPrice     = itemFromDb.BuyOutPrice,
                Picture         = itemFromDb.Picture,
                AuctionDuration = itemFromDb.EndTime.ToString(),
                Category        = new ItemDeleteCategoryViewModel
                {
                    Name = itemFromDb.Category.ToString()
                },
                Description  = itemFromDb.Description,
                AuctionHouse = itemFromDb.AuctionHouse.Name
            };


            this.ViewData["auctionHouses"] = auctionHouses.Select(auctionHouse =>
                                                                  new ItemDeleteCategoryViewModel
            {
                Name = auctionHouse.Name
            })
                                             .ToList();

            return(this.View(viewModel));
        }
예제 #2
0
        public async Task <IActionResult> Delete(int id, ItemDeleteViewModel itemDelete)
        {
            try
            {
                var item = await this.itemsService.DeleteByIdAsync(id);

                return(this.RedirectToAction(nameof(this.Index)));
            }
            catch (NullReferenceException e)
            {
                // TODO: Error message that item not exist
                // this.ModelState.Root.AttemptedValue = "ModelOnly";
                // this.ModelState.Root.RawValue = e.Message;
                this.ModelState.AddModelError(e.InnerException.Message, e.Message);
                return(this.View(itemDelete));
            }
        }
예제 #3
0
        public async Task <IActionResult> Delete(int id, ItemDeleteViewModel itemDelete)
        {
            var item = await this.itemsService.DeleteByIdAsync(id);

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