Ejemplo n.º 1
0
        //levantamento de €€
        public JsonResult CreateCoupon(int amount)
        {
            CouponCreate couponCreate = null;
            AccountController accountController = new AccountController();
            BtceApix btceApix = new BtceApix(key, secret);

            var User = accountController.GetUser(Request);
            if (User != null)
            {
                couponCreate = btceApix.CreateCoupon("EUR", amount);
                try
                {
                    if (couponCreate != null)
                    {
                        BetBitEntities betBitEntities = new BetBitEntities();
                        betBitEntities.Coupon.Add(new Coupon()
                        {
                            UserId = User.UserId,
                            CouponAmount = amount * (-1),
                            CouponCode = couponCreate.Coupon,
                            TransId = couponCreate.TransID,
                            CreateDate = DateTime.Now
                        });
                        betBitEntities.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("ola", ex);
                }

            }
            return Json(couponCreate, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 2
0
        public User GetUser(HttpRequestBase request)
        {
            User user = new User();

            HttpCookie myCookie = request.Cookies["BetBit"];
            if (myCookie == null)
            {

                var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var random = new Random();
                user.Username = new string(
                    Enumerable.Repeat(chars, 8)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());

                user.Password = new string(
                    Enumerable.Repeat(chars, 12)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());

                user.UserId = Guid.NewGuid();
                user.Balance = 0;

                myCookie = new HttpCookie("BetBit");
                myCookie.Value = user.UserId.ToString();
                myCookie.Expires = DateTime.Now.AddYears(1);
                Response.Cookies.Add(myCookie);

                BetBitEntities betBitEntities = new BetBitEntities();

                betBitEntities.Users.Add(new Users()
                {
                    UserId = user.UserId,
                    Username = user.Username,
                    Password = user.Password

                });

                betBitEntities.SaveChanges();
            }
            else
            {
                user.UserId = new Guid(myCookie.Value);

                BetBitEntities betBitEntities = new BetBitEntities();

                Users userFromBD = betBitEntities.Users.FirstOrDefault(i => i.UserId.Value.Equals(user.UserId));
                user.Username = userFromBD.Username;
                user.Password = userFromBD.Password;

                user.Balance = betBitEntities.Coupon.Where(i => i.UserId == user.UserId).Select(i => i.CouponAmount).DefaultIfEmpty(0).Sum();

            }
            return user;
        }
Ejemplo n.º 3
0
        public JsonResult ChangePassword(string username, string currentPassword, string newPassword)
        {
            BetBitEntities betBitEntities = new BetBitEntities();
            HttpCookie myCookie = Request.Cookies["BetBit"];
            //User user = new User();

            //get user
            var user = betBitEntities.Users.FirstOrDefault(i => i.Username.Equals(username) && i.Password.Equals(currentPassword));

            //new password
            if (user != null)
            {
                user.Password = newPassword;
                betBitEntities.SaveChanges();

                return Json(true, JsonRequestBehavior.AllowGet);
            }

            return Json(false, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 4
0
        public JsonResult RedeemCoupon(string coupon)
        {
            BtceApix btceApix = new BtceApix(key, secret);

            CouponResult couponResult = btceApix.RedeemCoupon(coupon);

            BetBitEntities betBitEntities = new BetBitEntities();
            AccountController accountController = new AccountController();
            betBitEntities.Coupon.Add(new Coupon()
                {
                    UserId = accountController.GetUser(Request).UserId,
                    CouponAmount = couponResult.CouponAmount,
                    CouponCode = coupon,
                    CreateDate = DateTime.Now
                });
            betBitEntities.SaveChanges();
            return Json(couponResult, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 5
0
        public JsonResult Logout()
        {
            User user = new User();
            HttpCookie myCookie = null;

            var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            var random = new Random();
            user.Username = new string(
                Enumerable.Repeat(chars, 8)
                          .Select(s => s[random.Next(s.Length)])
                          .ToArray());

            user.Password = new string(
                Enumerable.Repeat(chars, 12)
                          .Select(s => s[random.Next(s.Length)])
                          .ToArray());

            user.UserId = Guid.NewGuid();
            user.Balance = 0;

            myCookie = new HttpCookie("BetBit");
            myCookie.Value = user.UserId.ToString();
            myCookie.Expires = DateTime.Now.AddYears(1);
            Response.Cookies.Add(myCookie);

            BetBitEntities betBitEntities = new BetBitEntities();

            betBitEntities.Users.Add(new Users()
            {
                UserId = user.UserId,
                Username = user.Username,
                Password = user.Password,
                Balance = user.Balance
            });

            betBitEntities.SaveChanges();

            return Json(user, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 6
0
        public JsonResult UserLogin(string username, string password, string logout)
        {
            BetBitEntities betBitEntities = new BetBitEntities();
            HttpCookie myCookie = Request.Cookies["BetBit"];
            User user = new User();

            var User = betBitEntities.Users.FirstOrDefault(i => i.Username.Equals(username) && i.Password.Equals(password));

            if (User != null)
            {
                myCookie = new HttpCookie("BetBit");
                myCookie.Value = User.UserId.ToString();
                myCookie.Expires = DateTime.Now.AddYears(1);
                Response.Cookies.Add(myCookie);

                user.Username = User.Username;
                user.Password = User.Password;
                user.UserId = User.UserId.Value;
            }
            if (logout.Equals("true"))
            {
                Response.Cookies["BetBit"].Expires = DateTime.Now.AddDays(-1);
                myCookie = null;

                if (myCookie == null)
                    return Logout();
            }
            return Json(user, JsonRequestBehavior.AllowGet);
        }