Esempio n. 1
0
        public ActionResult Create([Bind(Include = "RentId,PriceToPay,Days,DateRent,DateReturn,DaysDiscount,RentsDiscount,Discount,RentAccepted,CarId,RentManagerId")] Rent rent)
        {
            //var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId();
                var rentManagerId = db.RentManagers.First(c => c.ApplicationUserId == userId).RentManagerId;
                var car = db.Cars.First(c => c.CarId == rent.CarId);

                DateTime date = DateTime.Now;
                rent.DateRent = date;
                TimeSpan days = rent.DateReturn - rent.DateRent;

                car.IsReserved = true;
                rent.Days = days.Days + 1;

                rent.RentManagerId = rentManagerId;

                if (rent.DateReturn <= rent.DateRent)
                {
                    return View("InvalidDate");
                }

                db.Rents.Add(rent);
                db.SaveChanges();

                var service = new RentManagerService(db);
                decimal price = service.Price(days.Days + 1, car.PricePerDay);
                service.RentsDiscountHandler(days.Days + 1, rent.RentId, rent.RentManagerId, price);
                return RedirectToAction("RedirectToPayment", new { id = rent.RentId });
            }
            return View("Index");
        }
Esempio n. 2
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.FirstName));

                    var service = new RentManagerService(HttpContext.GetOwinContext().Get<ApplicationDbContext>());
                    service.CreateRentManager(model.FirstName, model.LastName, user.Id);

                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // 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.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

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

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Esempio n. 3
0
 public ActionResult RedirectToPayment(Rent rents)
 {
     var rent = db.Rents.First(c => c.RentId == rents.RentId);
     var service = new RentManagerService(db);
     if (!service.ReservationTimer(rent.DateRent))
     {
         var car = db.Cars.FirstOrDefault(c => c.CarId == rent.CarId);
         car.IsReserved = false;
         car.IsRented = false;
         rent.RentAccepted = false;
         db.SaveChanges();
         return View("ReservationTimerErr");
     }
     return RedirectToAction("Payment", new {id = rent.RentId});
 }