Example #1
0
        public ActionResult Bid([Bind(Include = "ID,RollId,Lot,SpeciesCode,TagNr,Age,DateMeasured,HornLength,TipToTip,OtherInfo,DateAvailable,Male,Female,Young,Quantity,Quantity_Lot,SellerId,BuyerId,BiddingPrice,BidDateTime,BidTotalPrice,NewBidPrice,NewBidder,Picture,OnAuction,Sold,DateLoaded,DateSold,PicturePath,PictureName,Increments,ReservePrice,LotQ,DateTimeBid,DateTimeClose,CustomerNumber")] tblRoll tblRoll)
        {
            if (ModelState.IsValid)
            {
                BidController bd  = new BidController();
                Bid           bid = new Bid();
                bid.ID          = tblRoll.ID;
                bid.BuyerId     = Int32.Parse(tblRoll.CustomerNumber);
                bid.NewBidPrice = tblRoll.NewBidPrice;
                bid.RollId      = tblRoll.RollId;

                // Kry die user inligting
                tblCustomer tblCustomersLog = db.tblCustomers.FirstOrDefault(i => i.CustomerID == User.Identity.Name);
                if (tblCustomersLog != null)
                {
                    bid.UserID = tblCustomersLog.ID; // Kry ID van persoon wat ingelog het.
                }

                Bid dm = bd.BidLogic(bid); // Process bid!

                if (bid.bidToLow)
                {
                    TempData["msg"] = "<script>alert('Bidding price must be higher than current bid + increment');</script>";
                    return(RedirectToAction("Bid", tblRoll.ID));
                }
                if (bid.bidClosed)
                {
                    TempData["msg"] = "<script>alert('Bid has closed');</script>"; // Moet dit toets
                    return(RedirectToAction("Bid", tblRoll.ID));
                }

                return(RedirectToAction("Index", new { AuctionID = tblRoll.RollId }));
            }

            ViewBag.RollId  = new SelectList(db.ltRollDescriptions, "ID", "Description", tblRoll.RollId);
            ViewBag.BuyerId = new SelectList(db.tblCustomers, "ID", "CompanyName", tblRoll.BuyerId);
//            ViewBag.CustomerNumber = new SelectList(db.BuyerNoes, "CustomerID", "BuyerNumber", tblRoll.BuyerId);
            ViewBag.CustomerNumber = db.BuyerNoes.OrderBy(t => t.BuyerNumber).Where(g => g.CustomerID != null).Select(rr => new SelectListItem {
                Value = rr.CustomerID.ToString(), Text = rr.BuyerNumber + "   (" + rr.tblCustomer.CompanyName + ")"
            }).ToList();

            return(View(tblRoll));
        }
Example #2
0
        public ActionResult Bid([Bind(Include = "ID,RollId,Lot,SpeciesCode,TagNr,Age,DateMeasured,HornLength,TipToTip,OtherInfo,DateAvailable,Male,Female,Young,Quantity,Quantity_Lot,SellerId,BuyerId,BiddingPrice,BidDateTime,BidTotalPrice,NewBidPrice,NewBidder,Picture,OnAuction,Sold,DateLoaded,DateSold,PicturePath,PictureName,Increments,ReservePrice,LotQ,DateTimeClose,CustomerNumber")] tblRoll tblRoll)
        {
            if (ModelState.IsValid)
            {
                // nuut
                BidController bd  = new BidController();
                Bid           bid = new Bid();
                bid.ID          = tblRoll.ID;
                bid.NewBidPrice = tblRoll.NewBidPrice;
                bid.RollId      = tblRoll.RollId;
                // Kry die user inligting

                //                var user = UserManager.FindByNameAsync("PIET");

                tblCustomer tblCustomersLog = db.tblCustomers.FirstOrDefault(i => i.CustomerID == User.Identity.Name);

                if (tblCustomersLog.PIN != tblRoll.CustomerNumber)
                {
                    TempData["msg"] = "<script>alert('Incorrect PIN');</script>";
                    return(RedirectToAction("Bid", tblRoll.ID));
                }
                if (tblCustomersLog != null)
                {
                    bid.BuyerId = tblCustomersLog.ID; // Kry ID van persoon wat ingelog het.
                    bid.UserID  = tblCustomersLog.ID; // Buyer is ook User.
                }

                Bid dm = bd.BidLogic(bid); // Process bid!

                if (bid.bidToLow)
                {
                    TempData["msg"] = "<script>alert('Bidding price must be higher than current bid + increment');</script>";
                    return(RedirectToAction("Bid", tblRoll.ID));
                }
                if (bid.bidClosed)
                {
                    TempData["msg"] = "<script>alert('Bid has closed');</script>"; // Moet dit toets
                    return(RedirectToAction("Bid", tblRoll.ID));
                }

                return(RedirectToAction("Index", new { AuctionID = tblRoll.RollId }));

                // end nuut
            }
            else
            {
                string initApp;

                if (Session["InitApp"] == null)
                {
                    Session["InitApp"] = "Web"; // creat InitApp as web init if nothing received
                }
                initApp = Session["InitApp"].ToString();

                if (initApp == "App")
                {
                    return(View("BidApp", tblRoll));
                }
                else
                {
                    return(View(tblRoll));
                }
            }
        }