//1-передел. визуал
        //2- при клике по "сделать ставку" - для хозяина лота будет блокировка! (контроль в клиенте)
        public async Task <ActionResult> Details(int?auctionId)
        {
            if (auctionId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Auction auction = await db.Auctions.FindAsync(auctionId);

            if (auction == null)
            {
                return(HttpNotFound());
            }
            BetAuction topBet = db.BetAuction.Where(b => b.AuctionId == auction.Id).ToList().Last();

            ViewBag.TopBet = topBet;

            var accountId = Session["accountId"] ?? 0;

            if ((int)accountId == 0)
            {
                return(RedirectToAction("Index", new { alert = "Время сессии истекло. Выйдите и зайдите снова!" }));
            }
            Client client = db.Clients.FirstOrDefault(c => c.AccountId == (int)accountId);

            ViewBag.Client = client; //нужно для запроса с представл. Details.html  на созд. ставки -> BetAuction/Create()
            return(View(auction));
        }
        private static void CreateBetAuctionEntity(AuctionEditVM editVM, Auction auction, Client client)
        {
            BetAuction betAuction = new BetAuction {
                Auction = auction, Bet = editVM.Price, Client = client
            };

            db.BetAuction.Add(betAuction);
        }
Example #3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            BetAuction betAuction = await db.BetAuction.FindAsync(id);

            db.BetAuction.Remove(betAuction);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Example #4
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,AuctionId,ClientId,Bet")] BetAuction betAuction)
        {
            if (ModelState.IsValid)
            {
                db.Entry(betAuction).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.AuctionId = new SelectList(db.Auctions, "Id", "Description", betAuction.AuctionId);
            ViewBag.ClientId  = new SelectList(db.Clients, "Id", "Id", betAuction.ClientId);
            return(View(betAuction));
        }
Example #5
0
        // GET: BetAuctions/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BetAuction betAuction = await db.BetAuction.FindAsync(id);

            if (betAuction == null)
            {
                return(HttpNotFound());
            }
            return(View(betAuction));
        }
Example #6
0
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BetAuction betAuction = await db.BetAuction.FindAsync(id);

            if (betAuction == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AuctionId = new SelectList(db.Auctions, "Id", "Description", betAuction.AuctionId);
            ViewBag.ClientId  = new SelectList(db.Clients, "Id", "Id", betAuction.ClientId);
            return(View(betAuction));
        }
Example #7
0
        //[ValidateAntiForgeryToken] //не приним. JsonRequest??????
        public async Task <ActionResult> Create(BetAuction betAuction, JsonRequestCreateBet data)
        {
            if (ModelState.IsValid && betAuction.AuctionId != 0)
            {
                db.BetAuction.Add(betAuction);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else        //возвр. Json в Details.html
            {
                string  messageError = "";
                int     auctionId    = int.Parse(data.AuctionId);
                int     clientId     = int.Parse(data.ClientId);
                decimal bet          = decimal.Parse(data.Bet);
                try {
                    var myBetAuction = new BetAuction {
                        AuctionId = auctionId, ClientId = clientId, Bet = bet
                    };
                    var repeatBet = await db.BetAuction.FirstOrDefaultAsync(b => b.AuctionId == auctionId && b.ClientId == clientId && b.Bet == bet);

                    if (repeatBet != null)
                    {
                        messageError = "Такая ставка уже есть. Попробуйте снова!";
                        return(new JsonResult {
                            Data = messageError, JsonRequestBehavior = JsonRequestBehavior.DenyGet
                        });
                    }
                    db.BetAuction.Add(myBetAuction);
                    await db.SaveChangesAsync();

                    messageError = "Ставка сделана. Данные добавлены!";
                }
                catch (Exception e) {
                    messageError = "Произошла ошибка. Данные не были добавлены!";
                }
                return(new JsonResult {
                    Data = messageError, JsonRequestBehavior = JsonRequestBehavior.DenyGet
                });
            }
        }
 private void Update(BetAuction betAuction)
 {
     unitOfWork.BetAuctions.Update(betAuction);
 }
 private void Add(BetAuction betAuction)
 {
     unitOfWork.BetAuctions.Create(betAuction);
 }