示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("AuctionId,AuctionName,StartDate,EndDate")] Auction auction)
        {
            if (id != auction.AuctionId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(auction);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuctionExists(auction.AuctionId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(auction));
        }
        public async Task <IActionResult> Edit(int id, [Bind("MediaTypeID,MediaDescription")] MediaType mediaType)
        {
            if (id != mediaType.MediaTypeID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(mediaType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MediaTypeExists(mediaType.MediaTypeID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(mediaType));
        }
        public async Task <IActionResult> Edit(int id, [Bind("BidHistoryId,BidDate,BidAmount,ItemId")] BidHistory bidHistory)
        {
            if (id != bidHistory.BidHistoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bidHistory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BidHistoryExists(bidHistory.BidHistoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(bidHistory));
        }
        public async Task <IActionResult> Edit(int id, [Bind("sponsorID,sponsorName,sponsorEmail")] Sponsor sponsor)
        {
            if (id != sponsor.sponsorID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sponsor);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SponsorExists(sponsor.sponsorID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(sponsor));
        }
        public async Task <IActionResult> Edit(int id, CreateOrEditUserViewModel viewModel)
        {
            var user = viewModel.User;

            if (id != user.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                TempData["SuccessMessage"] = $"Successfully edited user #{user.UserId.ToString()}.";

                return(RedirectToAction("Index"));
            }
            return(await CreateOrEdit(viewModel));
        }
        public async Task <IActionResult> Edit(int id, [Bind("CategoryId,Name,Description")] Category category)
        {
            if (id != category.CategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.CategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
示例#7
0
        public async Task <IActionResult> Edit(int id, [Bind("RoleID,ShortDescription,UserRole")] Role role)
        {
            if (id != role.RoleID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(role);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoleExists(role.RoleID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(role));
        }
示例#8
0
        public async Task <IActionResult> Edit(int id, [Bind("ItemId,sponsorID,CategoryId,ItemName,ItemDescription,ItemValue,OpeningBid,BidIncrement,AuctionId")] Item item)
        {
            if (id != item.ItemId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(item);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ItemExists(item.ItemId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            //  ViewData["AuctionId"] = new SelectList(_context.Auctions, "AuctionID", "AuctionID", item.AuctionId);
            return(View(item));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,FwdDate,BankName,AuctionBidID,FwdRate,AmountBid,CouponAmount,WinAmount")] WinResults winResults)
        {
            if (id != winResults.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(winResults);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WinResultsExists(winResults.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuctionBidID"] = new SelectList(_context.AuctionBids, "ID", "ID", winResults.AuctionBidID);
            return(View(winResults));
        }
        public async Task <IActionResult> Edit(int id, [Bind("BidderID,FirstName,LastName,PhoneNumber,EmailAddress,IsRegistered,Password,Security")] Bidder bidder)
        {
            if (id != bidder.BidderID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bidder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BidderExists(bidder.BidderID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(bidder));
        }
示例#11
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,FwdDate,BankName,FwdRate,AmountBid,CouponAmount,Pips,BatchRef")] AuctionBid auctionBid)
        {
            if (id != auctionBid.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(auctionBid);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuctionBidExists(auctionBid.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(auctionBid));
        }
示例#12
0
        public IActionResult Delete(int id)
        {
            Auction target = _context.Auctions.SingleOrDefault(a => a.id == id);

            if (target == null)
            {
                return(RedirectToAction("Main"));
            }
            if (target.creator_id != HttpContext.Session.GetInt32("id"))
            {
                return(RedirectToAction("Main"));
            }
            if (target.top_bidder_id != 0)
            {
                User topBidder = _context.Users.SingleOrDefault(u => u.id == target.top_bidder_id);
                topBidder.wallet += target.top_bid;
                _context.Update(topBidder);
            }
            _context.Remove(target);
            _context.SaveChanges();
            return(RedirectToAction("Main"));
        }
示例#13
0
        public async Task <IActionResult> Edit(int id, ItemViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }

            if (!int.TryParse(viewModel.Sponsor, out var sponsorId))
            {
                ModelState.AddModelError("Sponsor", "Couldn't parse sponsor");
            }
            else if (!int.TryParse(viewModel.Category, out var categoryId))
            {
                ModelState.AddModelError("Category", "Couldn't parse category");
            }
            else if (string.IsNullOrWhiteSpace(viewModel.Name))
            {
                ModelState.AddModelError("Name", "The Name field is empty.");
            }
            else if (string.IsNullOrWhiteSpace(viewModel.Description))
            {
                ModelState.AddModelError("Description", "The Description field is empty.");
            }
            else if (string.IsNullOrWhiteSpace(viewModel.RetailPrice))
            {
                ModelState.AddModelError("RetailPrice", "The retail price field is empty.");
            }
            else if (string.IsNullOrWhiteSpace(viewModel.OfferExpires))
            {
                ModelState.AddModelError("OfferExpires", "The offer expires field is empty.");
            }
            else if (string.IsNullOrWhiteSpace(viewModel.Terms))
            {
                ModelState.AddModelError("Terms", "The terms and conditions field is empty.");
            }
            else
            {
                string retailPriceInput = viewModel.RetailPrice;

                if (Regex.IsMatch(retailPriceInput, @"^฿"))
                {
                    retailPriceInput = retailPriceInput.Substring(1);
                }

                if (!decimal.TryParse(retailPriceInput, out var retailPrice))
                {
                    ModelState.AddModelError("Retailprice", "Couldn't parse retail price");
                }
                else
                {
                    var item = _context.Items.SingleOrDefaultAsync(item0 => item0.Id == id).Result;

                    item.SponsorId    = sponsorId;
                    item.Name         = viewModel.Name;
                    item.Description  = viewModel.Description;
                    item.CategoryId   = categoryId;
                    item.RetailPrice  = retailPrice;
                    item.OfferExpires = viewModel.OfferExpires;
                    item.Terms        = viewModel.Terms;
                    try
                    {
                        _context.Update(item);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ItemExists(item.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    TempData["SuccessMessage"] = $"Successfully changed listing #{item.Id.ToString()}.";
                    return(RedirectToAction("Index"));
                }
            }

            var itemMedia = _context.ItemMedia
                            .AsNoTracking()
                            .Where(itemMedia0 => itemMedia0.ItemId == id);

            viewModel.MediaIds   = itemMedia.Select(itemMedia0 => itemMedia0.MediaId).ToList();
            viewModel.Sponsors   = new SelectList(_context.Sponsors, "Id", "Name", viewModel.Sponsor);
            viewModel.Categories = new SelectList(_context.Categories, "Id", "Name", viewModel.Category);

            return(View(viewModel));
        }