public ActionResult Create([Bind(Include = "ID,CustomerID,RollID,BuyerNumber")] BuyerNo buyerNo)
        {
            if (ModelState.IsValid)
            {
                // Kyk vir duplicates
                using (AuctionDBEntities db = new AuctionDBEntities()) // make sure to get the latest info from DB and not the immage of DB.
                {
                    BuyerNo buyerNoAfter = db.BuyerNoes.FirstOrDefault(i => i.RollID == buyerNo.RollID && i.BuyerNumber == buyerNo.BuyerNumber);
                    if (buyerNoAfter != null)                                                     // Lot bestaan reeds
                    {
                        TempData["msg"] = "<script>alert('Lot number already exists');</script>"; // Moet dit toets
                        int x = 1;
                        return(RedirectToAction("Create", new { AuctionID = buyerNo.RollID }));
//                        return View(buyerNo);
                    }
                }
                db.BuyerNoes.Add(buyerNo);
                db.SaveChanges();
                return(RedirectToAction("Index", new { AuctionID = buyerNo.RollID }));
            }

            ViewBag.CustomerID = new SelectList(db.tblCustomers, "ID", "CompanyName", buyerNo.CustomerID);
            ViewBag.RollID     = new SelectList(db.ltRollDescriptions, "ID", "Description", buyerNo.RollID);
            return(View(buyerNo));
        }
Exemplo n.º 2
0
 public ActionResult Login(User_table objUser)
 {
     if (ModelState.IsValid)
     {
         using (AuctionDBEntities db = new AuctionDBEntities()) {
             var obj = db.User_table.Where(a => a.user_name.Equals(objUser.user_name) && a.user_password.Equals(objUser.user_password)).FirstOrDefault();
             if (obj != null)
             {
                 Session["Id"]        = objUser.Id.ToString();
                 Session["user_name"] = objUser.user_name.ToString();
                 Session["isActive"]  = objUser.isActive.ToString();
                 return(RedirectToAction("Auction", "Home"));
             }
         }
     }
     return(View(objUser));
 }
Exemplo n.º 3
0
        // Hier
        public Bid BidLogic(Bid bid)
        {
            currentBuyer.NewBuyerHaveCellNumber = false;
            currentBuyer.OutBuyerHaveCellNumber = false;
            currentBuyer.NewBuyerID             = bid.BuyerId;     // Die nuwe id wat oorkom.

            using (AuctionDBEntities db = new AuctionDBEntities()) // make sure to get the latest info from DB and not the immage of DB.
            {
                tblRoll tblRollAfter = db.tblRolls.Find(bid.ID);   // find the latest info on db.
                if (tblRollAfter.Increments == null)
                {
                    tblRollAfter.Increments = 0;
                }
                if (tblRollAfter.BiddingPrice == null)
                {
                    tblRollAfter.BiddingPrice = 0;
                }
                if (bid.NewBidPrice >= (tblRollAfter.BiddingPrice + tblRollAfter.Increments))
                {
                    double            ExtendBitTime;
                    bool              AuctionSMS         = false;
                    ltRollDescription ltRollDescriptions = db.ltRollDescriptions.Find(bid.RollId);
                    if (ltRollDescriptions != null)
                    {
                        ExtendBitTime = System.Convert.ToDouble(ltRollDescriptions.AuctionDelayTime);
                        AuctionSMS    = ltRollDescriptions.SmsNotification;
                    }
                    else
                    {
                        ExtendBitTime = 5;
                        AuctionSMS    = false;
                    }

                    //

                    bid.BidTotalPrice = bid.NewBidPrice * tblRollAfter.Quantity;
                    if (DateTime.Now <= tblRollAfter.DateTimeClose)
                    {
                        tblRollAfter.DateTimeBid = DateTime.Now;

                        if (DateTime.Now.AddMinutes(ExtendBitTime) >= tblRollAfter.DateTimeClose)
                        {
                            tblRollAfter.DateTimeClose = DateTime.Now.AddMinutes(ExtendBitTime); // add time before close.
                            db.UpdateBidTimeClose(bid.ID, tblRollAfter.DateTimeClose);
                        }
                        // Kan later weer terugsit.
                        //if (currentBuyer.NewBuyerID != tblRollAfter.BuyerId) // Not same outgoing and new bidder.
                        //{
                        // Get outgoing bidder info
                        tblCustomer tblCustomersOut = db.tblCustomers.Find(tblRollAfter.BuyerId);
                        currentBuyer.OutBuyerCell = tblCustomersOut.Phone;
                        if (currentBuyer.OutBuyerCell != null && currentBuyer.OutBuyerCell != "")
                        {
                            currentBuyer.OutBuyerHaveCellNumber = true;
                        }

                        // Get incomming bidder info

                        tblCustomer tblCustomersIn = db.tblCustomers.Find(currentBuyer.NewBuyerID);
                        currentBuyer.NewBuyerCell = tblCustomersIn.Phone;
                        if (currentBuyer.NewBuyerCell != null && currentBuyer.NewBuyerCell != "")
                        {
                            currentBuyer.NewBuyerHaveCellNumber = true;
                        }
                        //                        }

                        // Huidige koper

                        // Laaste voor update.
                        tblRoll tblRollLast = db.tblRolls.Find(bid.ID); // find the latest info on db.
                        if (tblRollLast.Increments == null)
                        {
                            tblRollLast.Increments = 0;
                        }
                        if (tblRollLast.BiddingPrice == null)
                        {
                            tblRollLast.BiddingPrice = 0;
                        }

                        if (bid.NewBidPrice >= (tblRollLast.BiddingPrice + tblRollLast.Increments))
                        {
                            if (tblRollLast.Quantity_Lot == "Lot")
                            {
                                bid.BidTotalPrice = bid.NewBidPrice;
                            }
                            else
                            {
                                bid.BidTotalPrice = bid.NewBidPrice * tblRollAfter.Quantity;
                            }

                            // Kry die Auction Buyer Nommer

                            string AuctionBuyerNumber;

                            BuyerNo buyeNo = db.BuyerNoes.FirstOrDefault(t => t.CustomerID == bid.BuyerId && t.RollID == bid.RollId);
                            if (buyeNo == null)
                            {
                                AuctionBuyerNumber = "INT " + bid.BuyerId.ToString();
                            }
                            else
                            {
                                AuctionBuyerNumber = "B " + buyeNo.BuyerNumber;
                            }

                            db.UpdateBidder(bid.ID, bid.BuyerId, bid.NewBidPrice, bid.BidTotalPrice, tblRollAfter.DateTimeBid, AuctionBuyerNumber);
                            db.AddBidHistory(bid.ID, bid.RollId, tblRollAfter.Lot, tblRollAfter.SellerId, bid.BuyerId, bid.NewBidPrice, bid.BidTotalPrice, tblRollAfter.DateTimeBid, bid.UserID);

                            // Laai defaults

                            DefaultSetupModel dm = LoadDefs(0); // Get the default values vir stuur van sms

                            // Sal net sms stuur as koper cell het, spesifieke auction verys dit en default is aan.

                            // Sms outgoing bidder
                            if (currentBuyer.OutBuyerHaveCellNumber && AuctionSMS && dm.SMSAllFunctionality == true && dm.SMSOutBidder == true)
                            {
                                string x = string.Format("{0:0,000}", bid.NewBidPrice);

                                smsMGT smg           = new smsMGT();
                                string messagestring = $"Silent auction: Your bid for Lot {tblRollAfter.Lot} has been exceeded. Current bid is : R {x}";
                                var    res           = smg.SendSingleSMS("1", currentBuyer.OutBuyerCell, messagestring);
                                if (res != "success")
                                {
                                    string    EmailSubject = "SMS NOT sent successfully";
                                    string    EMailBody    = $"SMS NOT sent successfully to out bidder {tblCustomersOut.CompanyName}" + ".  Error = " + res;
                                    sendEmail sm           = new sendEmail();
                                    string    emalres      = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                                }
                            }

                            // Sms new bidder.
                            if (currentBuyer.NewBuyerHaveCellNumber && AuctionSMS && dm.SMSAllFunctionality == true && dm.SMSNewBidder == true)
                            {
                                string y = string.Format("{0:0,000}", bid.NewBidPrice);

                                smsMGT smg           = new smsMGT();
                                string messagestring = $"Silent auction: Your bid for Lot {tblRollAfter.Lot} has been accepted. Your bid is : R {y}";
                                var    res           = smg.SendSingleSMS("1", currentBuyer.NewBuyerCell, messagestring);

                                if (res != "success")
                                {
                                    string    EmailSubject = "SMS NOT sent successfully";
                                    string    EMailBody    = $"SMS NOT sent successfully to new bidder {tblCustomersIn.CompanyName}" + "  " + res;
                                    sendEmail sm           = new sendEmail();
                                    string    emalres      = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                                }
                            }
                            if (bid.NewBidPrice >= (tblRollAfter.BiddingPrice + (tblRollAfter.Increments * 10)))
                            {
                                // email warning to NWWT
                                sendEmail sm           = new sendEmail();
                                string    y            = string.Format("{0:0,000}", bid.NewBidPrice);
                                string    z            = string.Format("{0:0,000}", tblRollAfter.BiddingPrice);
                                string    EmailSubject = "An extraordinary high bid received";
                                string    EMailBody    = $"An extraordinary high bid was made on Lot {tblRollAfter.Lot} by {tblCustomersIn.CompanyName}. The new bid is : R {y} and the previous bid was R {z}";
                                string    res          = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                            }
                        }
                        else
                        {
                            bid.bidToLow = true;
                        }
                    }
                    else
                    {
                        bid.bidClosed = true;
                    }
                }
                else
                {
                    bid.bidToLow = true;
                }
            }
            return(bid);
        }
Exemplo n.º 4
0
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult Index(RollAdminModel bid)
        //{
        //    int lot = bid.AuctionID;
        //    return View();
        //}
        public ActionResult Load(int?AuctionID)
        {
            using (AuctionDBEntities db = new AuctionDBEntities()) // make sure to get the latest info from DB and not the immage of DB.
            {
                foreach (var flex in db.FlexiBuyerNoes.Where(x => x.EMAIL != "" && x.EMAIL != null || (x.CEL != "" && x.CEL != null)).ToList())
                {
                    tblCustomer customer     = new tblCustomer();
                    tblCustomer customerFind = new tblCustomer();
                    customerFind = db.tblCustomers.FirstOrDefault(i => i.eMail == flex.EMAIL && i.eMail != "" && i.eMail != null);
                    if (customerFind == null) // Record met email bestaan nie. kyk of cell phone record bestaan.
                    {
                        customerFind = db.tblCustomers.FirstOrDefault(i => i.Phone == flex.CEL);
                    }

                    if (customerFind != null) // Update details
                    {
                        string a = flex.BSNR;
                    }
                    else // Add detail
                    {
                        customer.CustomerID    = flex.EMAIL;
                        customer.eMail         = flex.EMAIL;
                        customer.CompanyName   = flex.CUST_NAME;
                        customer.ContactPerson = flex.QFIND;
                        customer.Phone         = flex.CEL;
                        customer.CellPhone     = flex.TEL;
                        customer.VATNr         = flex.VATNR;
                        if (flex.VATNR != "" && flex.VATNR != null)
                        {
                            customer.VATRegistered = true;
                        }
                        else
                        {
                            customer.VATRegistered = false;
                        }
                        customer.Active = true;
                        db.AddCustomerFlex(customer.CustomerID, customer.CompanyName, customer.ContactPerson, customer.eMail, customer.CellPhone, customer.Phone, customer.VATNr, customer.VATRegistered, customer.Active);
                    }
                } // end of flex
                foreach (var flexBN in db.FlexiBuyerNoes.Where(x => x.EMAIL != "" && x.EMAIL != null || (x.CEL != "" && x.CEL != null)).ToList())
                {
                    // Kry customer ID
                    tblCustomer customerFindBN = new tblCustomer();

                    customerFindBN = db.tblCustomers.FirstOrDefault(i => i.eMail == flexBN.EMAIL && i.eMail != "" && i.eMail != null);
                    if (customerFindBN == null) // Record met email bestaan nie. Kyk of cell phone record bestaan.
                    {
                        customerFindBN = db.tblCustomers.FirstOrDefault(i => i.Phone == flexBN.CEL);
                    }

                    if (customerFindBN != null) // Update details  // Behoort almal te gekry het
                    {
                        BuyerNo buyerNoAfter = db.BuyerNoes.FirstOrDefault(i => i.RollID == AuctionID && i.BuyerNumber == flexBN.BSNR);
                        if (buyerNoAfter != null) // Lot bestaan reeds
                        {
                            // Ignore
                        }
                        else
                        {
                            BuyerNo buyerNo = new BuyerNo();

                            buyerNo.BuyerNumber = flexBN.BSNR;
                            buyerNo.CustomerID  = customerFindBN.ID;
                            buyerNo.RollID      = AuctionID;

                            db.BuyerNoes.Add(buyerNo);
                            db.SaveChanges();
                        }
                    }
                } // end of flec bn
//                return RedirectToAction("Index");
            }     // end of using
            TempData["msg"] = "<script>alert('Load completed');</script>";

            return(RedirectToAction("Index"));
        } // end of load