예제 #1
0
        public ActionResult Getcodebyemail(int Idd)
        {
            Random rand   = new Random();
            long   ranNum = rand.Next();
            var    id     = Convert.ToInt32(Session["UserId"]);
            var    client = DB.Clients.Single(c => c.userId == id);
            var    user   = DB.Users.Single(c => c.Id == id);
            var    gift   = DB.Offers.Single(c => c.Id == Idd);


            if (client.Points >= gift.requiredPoint)
            {
                var offerwinners = new OfferWinner();
                offerwinners.clientId = client.Id;
                offerwinners.offerId  = gift.Id;
                DB.OfferWinners.Add(offerwinners);
                DB.SaveChanges();

                SendMail(user, ranNum);
                client.Points = client.Points - gift.requiredPoint;
                DB.SaveChanges();
                string msg = "email";
                return(Content(msg));
            }
            else
            {
                string msg = "error";
                return(Content(msg));
            }
        }
예제 #2
0
        public ActionResult Getcode(int Id)
        {
            var gift = DB.Offers.Single(c => c.Id == Id);

            string          txtQRCode   = gift.Qr_Gift;
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(txtQRCode, QRCodeGenerator.ECCLevel.Q);
            QRCode          qrCode      = new QRCode(qrCodeData);

            //System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
            //imgBarCode.Height = 150;
            //imgBarCode.Width = 150;
            using (Bitmap bitMap = qrCode.GetGraphic(20))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    ViewBag.imageBytes = ms.ToArray();
                    //imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                }
            }



            //Random rand = new Random();
            //int ranNum = rand.Next();
            var id   = Convert.ToInt32(Session["UserId"]);
            var user = DB.Clients.Single(c => c.userId == id);


            //  var offerWin = DB.Offers.ToList();



            if (user.Points >= gift.requiredPoint)
            {
                var offerwinners = new OfferWinner();
                offerwinners.clientId = user.Id;
                offerwinners.offerId  = gift.Id;
                DB.OfferWinners.Add(offerwinners);
                DB.SaveChanges();
                user.Points = user.Points - gift.requiredPoint;
                DB.SaveChanges();
                return(PartialView("codepartial"));
            }
            else
            {
                string msg = "error";
                return(Content(msg));
            }
        }