예제 #1
0
        public ActionResult Register()
        {
            // FB Added
            string aid = "0";
            int?   rollID;

            if (Session["auctionID"] == null)
            {
                rollID = 0;
            }
            else
            {
                aid    = Session["auctionID"].ToString();
                rollID = Int32.Parse(aid);
            }


            // Find Auction record for role roll id.

            BidController     bd = new BidController();
            DefaultSetupModel dm = bd.LoadDefs(rollID); // Get the default values

            ViewBag.BackgroundColor     = dm.BackgroundColor;
            ViewBag.TexColor            = dm.FontColor;
            ViewBag.LogoBackgroundColor = dm.LogoBackgroundColor;
            ViewBag.LogoPath            = dm.LogoPath;
            ViewBag.LogoName            = dm.LogoName;

            return(View());
        }
예제 #2
0
        // GET: RollDisplay
        public ActionResult Index()
        {
            string sessionID = "0";

            if (Session["auctionID"] == null) // Must have selected an auction.
            {
                // Gaan terug na roll
                TempData["msg"] = "<script>alert('Select an auction first');</script>";
                return(RedirectToAction("Index", "Home"));
            }

            sessionID = Session["auctionID"].ToString();
            int AuctionID = AuctionID = Int32.Parse(sessionID);

            BidController     bd = new BidController();
            DefaultSetupModel dm = bd.LoadDefs(AuctionID); // Get the default values

            int?rollID = dm.ID;

            ViewBag.BackgroundColor     = dm.BackgroundColor;
            ViewBag.TexColor            = dm.FontColor;
            ViewBag.LogoBackgroundColor = dm.LogoBackgroundColor;
            ViewBag.ImagePath           = dm.RollImagePath;
            ViewBag.LogoPath            = dm.LogoPath;
            ViewBag.LogoName            = dm.LogoName;
            ViewBag.RefreshTime         = dm.RefreshTime.ToString();
            ViewBag.ImagePath           = dm.RollImagePath;
            ViewBag.emptyMessage        = dm.message;

            string initApp = "Web";

            if (Session["InitApp"] != null)
            {
                initApp = Session["InitApp"].ToString();
            }


            if (initApp == "App")
            {
                ViewBag.Columns = 0;
            }
            else
            {
                ViewBag.Columns = 2;
            }


            var tblRolls = db.tblRolls.Include(t => t.ltRollDescription).Include(t => t.ltRollDescription1).Include(t => t.ltSpecy).Include(t => t.tblCustomer).Where(t => t.RollId == rollID);

            return(View(tblRolls.ToList()));
        }
        // GET: BuyerNumber/Create
        public ActionResult Create(RollAdminModel rollAdminModel)
        {
            if (Session["SelectedAuctionID"] == null) // behoort te bestaan
            {
                BidController     bd = new BidController();
                DefaultSetupModel dm = bd.LoadDefs(0); // Get the default values
                rollAdminModel.AuctionID     = dm.DefaultAuction;
                Session["SelectedAuctionID"] = rollAdminModel.AuctionID.ToString();
            }
            else
            {
                int Selectedauction = Int32.Parse(Session["SelectedAuctionID"].ToString());
                rollAdminModel.AuctionID = Selectedauction;
            }

            ViewBag.CustomerID = new SelectList(db.tblCustomers, "ID", "CompanyName");
            ViewBag.RollID     = new SelectList(db.ltRollDescriptions, "ID", "Description", rollAdminModel.AuctionID);
            ViewBag.rollIDBag  = rollAdminModel.AuctionID;
            return(View());
        }
예제 #4
0
        // GET: RollAdmin
        public ActionResult Index(RollAdminModel rollAdminModel)
        {
            if (Session["SelectedAuctionID"] == null) // IF sesion var not created yet, create
            {
                Session["SelectedAuctionID"] = "0";
            }
            if (rollAdminModel.AuctionID == 0 || rollAdminModel.AuctionID == null) // kry gegewens vanag default table.
            {
                BidController     bd = new BidController();
                DefaultSetupModel dm = bd.LoadDefs(0); // Get the default values
                rollAdminModel.AuctionID = dm.DefaultAuction;
            }

            Session["SelectedAuctionID"] = rollAdminModel.AuctionID.ToString(); // Set sesion var met wat geselekteer is

            ViewBag.rollIDBag = rollAdminModel.AuctionID;
            ViewBag.AuctionID = new SelectList(db.ltRollDescriptions, "Id", "Description", rollAdminModel.AuctionID);

            var tblRolls = db.tblRolls.Include(t => t.ltRollDescription).Include(t => t.ltRollDescription1).Include(t => t.ltSpecy).Include(t => t.tblCustomer).Include(t => t.tblCustomer1).Where(t => t.RollId == rollAdminModel.AuctionID);

            return(View(tblRolls.ToList()));
        }
예제 #5
0
        // GET: RollAdmin/Create
        public ActionResult Create()
        {
            int?AuctionID;

            if (Session["SelectedAuctionID"] == null) // IF sesion var not created yet, create
            {
                BidController     bd = new BidController();
                DefaultSetupModel dm = bd.LoadDefs(0);               // Get the default values
                AuctionID = dm.DefaultAuction;
                Session["SelectedAuctionID"] = AuctionID.ToString(); // Set sesion var met wat geselekteer is
            }
            else
            {
                AuctionID = Int32.Parse(Session["SelectedAuctionID"].ToString());
            }

            ViewBag.auctionID = AuctionID;
            ViewBag.RollId    = new SelectList(db.ltRollDescriptions, "ID", "Description", AuctionID);

            //            ViewBag.RollId = new SelectList(db.ltRollDescriptions, "ID", "Description");
            ViewBag.SpeciesCode = new SelectList(db.ltSpecies, "ID", "Description");
            ViewBag.BuyerId     = new SelectList(db.tblCustomers, "ID", "CompanyName");
            ViewBag.SellerId    = new SelectList(db.tblCustomers, "ID", "CompanyName");
            tblRoll           rol = new tblRoll();
            ltRollDescription ltRollDescription = db.ltRollDescriptions.Find(AuctionID);

            if (ltRollDescription != null)
            {
                rol.Quantity_Lot  = "Animal";
                rol.OnAuction     = true;
                rol.DateTimeClose = ltRollDescription.EndDate;
                rol.DateLoaded    = DateTime.Now;
                rol.BidOpen       = true;
            }

            return(View(rol));
        }
예제 #6
0
        // GET: Bid/Edit/5
        public ActionResult Bid(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblRoll tblRoll = db.tblRolls.Find(id);

            // store outgoing bidders details

            currentBuyer.NewBuyerID = tblRoll.BuyerId;  // get the new buyer buyer's ID

            if (tblRoll == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RollId      = new SelectList(db.ltRollDescriptions, "ID", "Description", tblRoll.RollId);
            ViewBag.RollId      = new SelectList(db.ltRollDescriptions, "ID", "Description", tblRoll.RollId);
            ViewBag.SpeciesCode = new SelectList(db.ltSpecies, "ID", "Description", tblRoll.SpeciesCode);
            ViewBag.BuyerId     = new SelectList(db.tblCustomers, "ID", "CustomerID", tblRoll.BuyerId);
            ViewBag.SellerId    = new SelectList(db.tblCustomers, "ID", "CustomerID", tblRoll.SellerId);

            if (tblRoll.BiddingPrice == null)
            {
                tblRoll.BiddingPrice = 0;
            }
            if (tblRoll.Increments == null)
            {
                tblRoll.Increments = 0;
            }
            if (tblRoll.Quantity == null)
            {
                tblRoll.Quantity = 1;
            }

            // Get defauls
            string sessionID = "0";
            int    AuctionID = 0;

            if (Session["auctionID"] != null) // Should never be null
            {
                sessionID = Session["auctionID"].ToString();
                AuctionID = Int32.Parse(sessionID);
            }

            DefaultSetupModel dm = LoadDefs(AuctionID); // Get the default values

            int?rollID = dm.ID;

            ViewBag.BackgroundColor     = dm.BackgroundColor;
            ViewBag.TexColor            = dm.FontColor;
            ViewBag.LogoBackgroundColor = dm.LogoBackgroundColor;
            ViewBag.ImagePath           = dm.RollImagePath;
            ViewBag.LogoPath            = dm.LogoPath;
            ViewBag.LogoName            = dm.LogoName;
            ViewBag.RefreshTime         = dm.RefreshTime.ToString();
            ViewBag.ImagePath           = dm.RollImagePath;
            ViewBag.emptyMessage        = dm.message;
            ViewBag.RollImageBackColor  = dm.RollImagesBackColor;

            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));
            }
        }
예제 #7
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);
        }
예제 #8
0
        public DefaultSetupModel LoadDefs(int?AuctionID)
        {
            DefaultSetupModel ds = new DefaultSetupModel();

            // Laai eers alles vanaf DefaultSetup table.

            DefaultSetup defaultSetup = db.DefaultSetups.FirstOrDefault(t => t.Active == true);

            if (defaultSetup != null)                          // het gekry.
            {
                ds.ID                             = AuctionID; // Het gekry en rollID is dus reg.
                ds.Description                    = defaultSetup.Description;
                ds.BackgroundColor                = defaultSetup.BackgroundColor;
                ds.FontColor                      = defaultSetup.FontColor;
                ds.LogoBackgroundColor            = defaultSetup.LogoBackgroundColor;
                ds.RefreshTime                    = defaultSetup.RefreshTime.ToString();
                ds.RollImagePath                  = defaultSetup.RollImagesPath;
                ds.Active                         = defaultSetup.Active;
                ds.LogoPath                       = defaultSetup.LogoPath;
                ds.LogoName                       = defaultSetup.LogoName;
                ds.SmallLogoName                  = defaultSetup.LogoPath;
                ds.RollImagePath                  = defaultSetup.RollImagesPath;
                ds.AuctionDelayTime               = defaultSetup.AuctionDelayTime.ToString();
                ds.SMSNewBidder                   = defaultSetup.SmsNotification;
                ds.SMSAllFunctionality            = defaultSetup.SMSAllFunctionality;
                ds.SMSCustRegistration            = defaultSetup.SMSCustRegistration;
                ds.SMSConfirmationLoginRequired   = defaultSetup.SMSConfirmationLoginRequired;
                ds.emailConfirmRegistration       = defaultSetup.emailConfirmRegistration;
                ds.emailConfirmationLoginRequired = defaultSetup.emailConfirmationLoginRequired;
                ds.BackgroundColorHome            = defaultSetup.BackgroundColorHome;
                ds.DispLines                      = defaultSetup.DispLines;
                ds.DispColumns                    = defaultSetup.DispColumns;
                ds.pageSize                       = ds.DispLines * ds.DispColumns;
                ds.RollDispRefreshRate            = defaultSetup.RollDispRefreshRate;

                ds.HomePeriodDescription          = defaultSetup.HomePeriodDescription;
                ds.HomePeriodDescriptionTextColor = defaultSetup.HomePeriodDescriptionTextColor;
                ds.HomePeriodDescriptionBackColor = defaultSetup.HomePeriodDescriptionBackColor;
                ds.ActionTextColor = defaultSetup.ActionTextColor;
                ds.ActionBackColor = defaultSetup.ActionBackColor;



                if (defaultSetup.DefaultAuction != null)
                {
                    ds.DefaultAuction = defaultSetup.DefaultAuction;
                }
                else
                {
                    ds.DefaultAuction = 0;
                }
                ds.SMSOutBidder = defaultSetup.smsOutBidder;


                ds.message = "Please select an Auction";
            }

            if (AuctionID != 0) // Laai rol spesifieke inligting
            {
                ltRollDescription ltRollDescriptions = db.ltRollDescriptions.Find(AuctionID);
                if (ltRollDescriptions != null)                         // het gekry.
                {
                    ds.ID                       = AuctionID;            // Het gekry en rollID is dus reg.
                    ds.AuctionID                = AuctionID.ToString(); // String van ID
                    ds.Description              = ltRollDescriptions.Description;
                    ds.BackgroundColor          = ltRollDescriptions.BackgroundColor;
                    ds.FontColor                = ltRollDescriptions.FontColor;
                    ds.LogoBackgroundColor      = ltRollDescriptions.LogoBackgroundColor;
                    ds.RefreshTime              = ltRollDescriptions.RefreshTime.ToString();
                    ds.RollImagePath            = ltRollDescriptions.RollImagesPath;
                    ds.Active                   = ltRollDescriptions.Active;
                    ds.LogoPath                 = ltRollDescriptions.LogoPath;
                    ds.LogoName                 = ltRollDescriptions.LogoName;
                    ds.SmallLogoName            = ltRollDescriptions.LogoPath;
                    ds.RollImagePath            = ltRollDescriptions.RollImagesPath;
                    ds.AuctionDelayTime         = ltRollDescriptions.AuctionDelayTime.ToString();
                    ds.SMSNewBidder             = ltRollDescriptions.SmsNotification;
                    ds.SMSOutBidder             = ltRollDescriptions.smsOutBidder;
                    ds.RollImagesBackColor      = ltRollDescriptions.RollImagesBackColor;
                    ds.RollActionBidColor       = ltRollDescriptions.RollActionBidColor;
                    ds.RollActionBackIndexColor = ltRollDescriptions.RollActionBackIndexColor;

                    ds.HomePeriodDescription          = ltRollDescriptions.HomePeriodDescription;
                    ds.HomePeriodDescriptionTextColor = ltRollDescriptions.HomePeriodDescriptionTextColor;
                    ds.HomePeriodDescriptionBackColor = ltRollDescriptions.HomePeriodDescriptionBackColor;
                    ds.ActionTextColor = ltRollDescriptions.ActionTextColor;
                    ds.ActionBackColor = ltRollDescriptions.ActionBackColor;

                    ds.message = "Roll not loaded yet. Will be available soon!";
                }
            }
            return(ds);
        }
예제 #9
0
        // GET: Bid

        public ActionResult Index(int?AuctionID)
        {
            // Get defauls


            string sessionID = "0";

            if (AuctionID != null && AuctionID != 0) // Eerste keer
            {
                Session["auctionID"] = AuctionID;
            }
            else // Daar na sal Session 'n waarde he.
            {
                sessionID = Session["auctionID"].ToString();
                AuctionID = Int32.Parse(sessionID);
            }
            if ((AuctionID == null || AuctionID == 0) && Session["auctionID"] == null) // Must have selected an auction.
            {
                // Gaan terug na roll
                TempData["msg"] = "<script>alert('Select an auction first');</script>";
                return(RedirectToAction("Index", "Home"));
            }

            sessionID = Session["auctionID"].ToString();

            DefaultSetupModel dm = LoadDefs(AuctionID); // Get the default values

            int?rollID = dm.ID;

            ViewBag.BackgroundColor          = dm.BackgroundColor;
            ViewBag.TexColor                 = dm.FontColor;
            ViewBag.LogoBackgroundColor      = dm.LogoBackgroundColor;
            ViewBag.ImagePath                = dm.RollImagePath;
            ViewBag.LogoPath                 = dm.LogoPath;
            ViewBag.LogoName                 = dm.LogoName;
            ViewBag.RefreshTime              = dm.RefreshTime.ToString();
            ViewBag.ImagePath                = dm.RollImagePath;
            ViewBag.emptyMessage             = dm.message;
            ViewBag.RollImageBackColor       = dm.RollImagesBackColor;
            ViewBag.RollActionBidColor       = dm.RollActionBidColor;
            ViewBag.RollActionBackIndexColor = dm.RollActionBackIndexColor;


            var tblRolls = db.tblRolls.Include(t => t.ltRollDescription).Include(t => t.ltRollDescription1).Include(t => t.ltSpecy).Include(t => t.tblCustomer).Include(t => t.tblCustomer1).Where(t => t.OnAuction && t.DateTimeClose >= DateTime.Now && t.RollId == rollID);

            //tblRoll time = new tblRoll();
            //ViewBag.TimeSpan = time.DateTimeClose - DateTime.Now;

            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("IndexApp", tblRolls.ToList()));
            }
            else
            {
                return(View(tblRolls.ToList())); // Web page
            }
        }
예제 #10
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            BidController     loadDefs = new BidController();
            DefaultSetupModel dms      = loadDefs.LoadDefs(0); // Get the default values

            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

                if (user == null)
                {
                    ViewBag.errorMessage = "Email address provided is not registered. Please use correct email address or register as user";
                    return(View("Error"));
                }

                if (dms.emailConfirmationLoginRequired == true)
                {
                    if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                    {
                        // Don't reveal that the user does not exist or is not confirmed
                        // return View("ForgotPasswordConfirmation"); // Moet error gee.
                        ViewBag.errorMessage = "Email address not confirmed";
                        return(View("Error"));
                    }
                }
                if (dms.SMSConfirmationLoginRequired == true)
                {
                    if (user == null || !(await UserManager.IsPhoneNumberConfirmedAsync(user.Id)))
                    {
                        // Don't reveal that the user does not exist or is not confirmed
                        //                        return View("ForgotPasswordConfirmation"); // Moet error gee.
                        ViewBag.errorMessage = "Cell Phone number not confirmed";
                        return(View("Error"));
                    }
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link

                //string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                //var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                // Fouche
                bool confirmation = false;
                // Stuur confirmation email as nodig
                if (dms.emailConfirmRegistration == true)
                {
                    string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                    //                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");
                    var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
                                      + "before you can log in.";
                    confirmation = true;
                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                }
                if (dms.SMSAllFunctionality == true && dms.SMSCustRegistration == true)
                {
                    // Generate OTP
                    var smscode = await UserManager.GenerateChangePhoneNumberTokenAsync(user.Id, user.PhoneNumber);

                    // FB added
                    smsMGT smg           = new smsMGT();
                    string messagestring = "Your security code for Silent Auction is: " + smscode;
                    var    res           = smg.SendSingleSMS("1", user.PhoneNumber, messagestring);
                    if (res != "success")
                    {
                        string    EmailSubject = "OTP SMS NOT sent successfully";
                        string    EMailBody    = $"OTP SMS NOT sent successfully to customer {user.CompanyName}" + " Forgot Password " + ".  Error = " + res;
                        sendEmail sm           = new sendEmail();
                        string    emalres      = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                        ViewBag.errorMessage = "Cell Phone number not correct. Log in and provide correct number or contact NWWT at [email protected]";
                        return(View("Error"));
                    }


                    //
                    confirmation = true;
                    return(RedirectToAction("VerifyPhoneNumberPasswordChange", new { PhoneNumber = user.PhoneNumber, id = user.Id }));
                }
                if (!confirmation)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    //                    return RedirectToAction("Index", "Home");
                    return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
                }
                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #11
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            // FB Added
            string aid = "0";
            int?   rollID;

            if (Session["auctionID"] == null)
            {
                rollID = 0;
            }
            else
            {
                aid    = Session["auctionID"].ToString();
                rollID = Int32.Parse(aid);
            }

            BidController     bd = new BidController();
            DefaultSetupModel dm = bd.LoadDefs(rollID); // Get the default values

            ViewBag.BackgroundColor     = dm.BackgroundColor;
            ViewBag.TexColor            = dm.FontColor;
            ViewBag.LogoBackgroundColor = dm.LogoBackgroundColor;
            ViewBag.LogoPath            = dm.LogoPath;
            ViewBag.LogoName            = dm.LogoName;

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    CompanyName = model.CompanyName, PhoneNumber = model.PhoneNumber, UserName = model.Email, Email = model.Email, CustomerID = model.CustomerID, ContactPerson = model.ContactPerson, ContactCellPhone = model.ContactCellPhone, PIN = model.PIN
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                // User is created in Accounts table

                if (result.Succeeded)
                {
                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.CompanyName));

                    // FB added this
                    // User is successfully created in Accounts table.
                    // Create Customer record with Basic info al is die inligting nie bevestig deur email of sms
                    //

                    tblCustomer tblCustomers  = new tblCustomer();
                    tblCustomer tblCustomerEx = db.tblCustomers.FirstOrDefault(i => i.CustomerID == model.Email);
                    string      companyName;
                    string      Email;

                    if (tblCustomerEx == null)                    // voeg by
                    {
                        tblCustomers.CustomerID    = model.Email; // Kan dalk later verander.
                        tblCustomers.CompanyName   = model.CompanyName;
                        tblCustomers.CompanyID     = model.CustomerID;
                        tblCustomers.eMail         = model.Email;
                        tblCustomers.Phone         = model.PhoneNumber;
                        tblCustomers.ContactPerson = model.ContactPerson;
                        tblCustomers.CellPhone     = model.ContactCellPhone;
                        tblCustomers.Active        = true;
                        tblCustomers.VATRegistered = false;
                        tblCustomers.PIN           = model.PIN;
                        companyName = model.CompanyName;
                        Email       = model.Email;

                        db.tblCustomers.Add(tblCustomers);
                        db.SaveChanges();
                    }
                    else
                    {
                        tblCustomer tblCustomersF = db.tblCustomers.FirstOrDefault(i => i.CustomerID == model.Email);
                        db.Entry(tblCustomersF).State = EntityState.Modified;
                        tblCustomersF.CompanyName     = model.CompanyName;
                        tblCustomersF.CompanyID       = model.CustomerID;
                        tblCustomersF.eMail           = model.Email;
                        tblCustomersF.Phone           = model.PhoneNumber;
                        tblCustomersF.ContactPerson   = model.ContactPerson;
                        tblCustomersF.CellPhone       = model.ContactCellPhone;
                        tblCustomersF.Active          = true;
                        tblCustomersF.VATRegistered   = false;
                        tblCustomersF.PIN             = model.PIN;
                        companyName = model.CompanyName;
                        Email       = model.Email;

                        db.SaveChanges();
                    }

                    BidController     loadDefs = new BidController();
                    DefaultSetupModel dms      = loadDefs.LoadDefs(0); // Get the default values
                    bool confirmation          = false;
                    // Stuur confirmation email as nodig
                    if (dms.emailConfirmRegistration == true)
                    {
                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                        string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");

                        ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
                                          + "before you can log in.";
                        await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        confirmation = true;
                    }
                    if (dms.SMSAllFunctionality == true && dms.SMSCustRegistration == true)
                    {
                        // Generate OTP
                        var smscode = await UserManager.GenerateChangePhoneNumberTokenAsync(user.Id, model.PhoneNumber);

                        // FB added
                        smsMGT smg           = new smsMGT();
                        string messagestring = "Your security code for Silent Auction is: " + smscode;
                        var    res           = smg.SendSingleSMS("1", model.PhoneNumber, messagestring);

                        if (res != "success")
                        {
                            string    EmailSubject = "OTP SMS NOT sent successfully";
                            string    EMailBody    = $"OTP SMS NOT sent successfully to new customer {model.CompanyName}" + ".  Error = " + res + " Number " + model.PhoneNumber;
                            sendEmail sm           = new sendEmail();
                            string    emalres      = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                            ViewBag.errorMessage = "Cell Phone number not correct. Log in and provide correct number or contact NWWT at [email protected]";
                            return(View("Error"));
                            /// FB
                        }
                        confirmation = true;
                        return(RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.PhoneNumber, id = user.Id, email = Email, compName = companyName }));
                    }
                    if (!confirmation)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToAction("Index", "Home"));
                    }
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #12
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // FB Added
            string aid = "0";
            int?   rollID;

            if (Session["auctionID"] == null)
            {
                rollID = 0;
            }
            else
            {
                aid    = Session["auctionID"].ToString();
                rollID = Int32.Parse(aid);
            }


            // Find user record for role id.

            BidController     bd = new BidController();
            DefaultSetupModel dm = bd.LoadDefs(rollID); // Get the default values

            ViewBag.BackgroundColor     = dm.BackgroundColor;
            ViewBag.TexColor            = dm.FontColor;
            ViewBag.LogoBackgroundColor = dm.LogoBackgroundColor;
            ViewBag.LogoPath            = dm.LogoPath;
            ViewBag.LogoName            = dm.LogoName;

            // Require the user to have a confirmed email before they can log on.
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user != null)
            {
                if (!await UserManager.IsEmailConfirmedAsync(user.Id) && dm.emailConfirmationLoginRequired == true)
                {
                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account-Resend");

                    ViewBag.errorMessage = "You must have confirmed your email to log on.";
                    return(View("Error"));
                }

                if (!await UserManager.IsPhoneNumberConfirmedAsync(user.Id) && dm.SMSConfirmationLoginRequired == true)
                {
                    // Stuur weer boodskap.

                    ViewBag.errorMessage = "You must confirmed your details before login. Re-send Code";
                    ViewBag.email        = model.Email;
                    return(View("ResentCode"));
                }
                // Fouche : Adde Active check
                tblCustomer tblCustomerEx = db.tblCustomers.FirstOrDefault(i => i.CustomerID == model.Email);

                if (tblCustomerEx != null)     // Customer bestaan
                {
                    if (!tblCustomerEx.Active) // Customer nie aangelog nie.
                    {
                        ViewBag.errorMessage = "Log in not authorised. Please contact NWWT at [email protected]";

                        // Stuur email vir NWWT
                        // email warning to NWWT
                        sendEmail sm           = new sendEmail();
                        string    EmailSubject = "An attempt to log in was made by a suspended customer";
                        string    EMailBody    = $"An attempt to log in was made by a suspended customer. Customer {tblCustomerEx.CompanyName}.";
                        string    res          = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);


                        return(View("Error"));
                    }
                }
            }


            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true

            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }