예제 #1
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            Money trueUserMoney = new Money();

            string identity2 = User.Identity.GetUserId();
            var userMoney2 = from m in db.Moneys
                            where m.Usuario == identity2
                            select m;
            foreach (Money m in userMoney2)
            {
                trueUserMoney = m;
            }


            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return View(trueUserMoney);
        }
예제 #2
0
        public ActionResult ChargingMoney(string chargedMoney)
        {
            if (User.Identity.IsAuthenticated)
            {
                Money trueUserMoney = new Money();
                string identity = User.Identity.GetUserId();
                var userMoney = from m in db.Moneys
                                where m.Usuario == identity
                                select m;

                foreach (Money money in userMoney)
                {
                    trueUserMoney = money;
                }

                decimal decimalChargedMoney;

                if (decimal.TryParse(chargedMoney, out decimalChargedMoney))
                {
                    trueUserMoney.Usuario = User.Identity.GetUserId();
                    var y = (from x in db.Moneys where x.Usuario == identity  select x).FirstOrDefault();
                    if(y != null)
                        db.Moneys.Remove(y);

                    trueUserMoney.UserMoney += decimalChargedMoney;

                    db.Moneys.Add(trueUserMoney);
                    db.SaveChanges();
                }
            }
            return RedirectToAction("Index");
        }
예제 #3
0
        public ActionResult Rent(int? id, int days)
        {
            Money trueUserMoney = new Money();

            string identity = User.Identity.GetUserId();

            var userMoney = from m in db.Moneys
                             where m.Usuario == identity
                             select m;
            foreach (Money m in userMoney)
            {
                trueUserMoney = m;
            }

            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Movie movie = db.Movies.Find(id);
            if (movie == null)
            {
                return HttpNotFound();
            }

            var rents = from r in db.Rents
                        where r.Usuario == identity
                        select r;

            Rent rent = new Rent();
            rent.Movie = movie;
            rent.Usuario = User.Identity.GetUserId();
            rent.MovieName = movie.Title;
            rent.UserName = User.Identity.GetUserId();

            foreach (Rent renta in rents)
            {
                if(rent.MovieName == renta.MovieName)
                    return RedirectToAction("Index");
            }
            if(trueUserMoney.UserMoney-movie.Price<=0)
            {
                return RedirectToAction("Index");
            }

            trueUserMoney.Usuario = User.Identity.GetUserId();
            var y = (from x in db.Moneys where x.Usuario == identity select x).FirstOrDefault();
            if (y != null)
                db.Moneys.Remove(y);

            trueUserMoney.UserMoney -= movie.Price*days;

            db.Moneys.Add(trueUserMoney);
            db.SaveChanges();

            rent.EndRentDate = DateTime.Now.AddDays(days).ToString();
            db.Rents.Add(rent);
            db.SaveChanges();

            return RedirectToAction("Index");
        }