Пример #1
0
        public async Task <IActionResult> Rent()
        {
            var rent = await this.rentsService.CreateOpenRentByUserIdAsync(this.User.Identity.Name);

            if (rent == null || rent.Products.Count() == 0)
            {
                return(this.RedirectToAction("Open"));
            }

            var rentProductInputModel = new RentProductInputModel()
            {
                FirstName   = rent.Customer.FirstName,
                LastName    = rent.Customer.LastName,
                PhoneNumber = rent.Customer.PhoneNumber,
            };

            return(this.View(rentProductInputModel));
        }
Пример #2
0
        public async Task <IActionResult> Rent(RentProductInputModel model)
        {
            var rent = await this.rentsService.CreateOpenRentByUserIdAsync(this.User.Identity.Name);

            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            rent.ShippingAddress      = model.City + ", " + model.PostalCode + Environment.NewLine + model.Address;
            rent.Recipient            = model.FirstName + " " + model.LastName;
            rent.RentDate             = model.RentDate;
            rent.ReturnDate           = model.ReturnDate.AddDays(1);
            rent.RecipientPhoneNumber = model.PhoneNumber;
            rent.Comment   = model.Comment;
            rent.Guarantee = rent.Products.Sum(x => Math.Round(x.Product.Price * GlobalConstants.GuaranteePercent));

            await this.rentsService.SetRentDetailsAsync(rent);

            return(this.RedirectToAction("Confirm"));
        }