Exemplo n.º 1
0
        public IActionResult ChangePackage(PackageDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                var package = _packageService.GetById(model.Id);

                if (package == null)
                {
                    return(NotFound());
                }
                var card = _cardService.GetCurrentUserCard(_userManager.GetUserId(HttpContext.User));
                if (card == null)
                {
                    return(NotFound());
                }
                card.Package = package;
                _cardService.Update(card);

                var cp = _cpService.GetByCardId(card.Id);
                cp.Package        = package;
                cp.ExpirationDate = DateTime.Now;
                cp.Status         = _statusService.GetByName("Recharged");
                _cpService.Update(cp);

                ViewBag.success = "success";
                ViewBag.msg     = "Your Package Has been Changed. You need to Recharged Your Package.";
                return(RedirectToAction("MyPackage"));
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var card = _cardService.GetCardByNumber(model.Customercard);

                if (!_customerService.IsCustomer(card.Id))
                {
                    var user = new ApplicationUser {
                        UserName = model.Email, Email = model.Email
                    };
                    var result = await _userManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        Customer cus = new Customer
                        {
                            ApplicationUser = user,
                            CustomerCard    = card,
                            CustomerName    = card.OwnerName
                        };

                        _customerService.Add(cus);

                        CustomerPackage cp = _customerPackage.GetByCardId(card.Id);
                        cp.Customer = cus;
                        _customerPackage.Update(cp);
                        await _userManager.AddToRoleAsync(user, "User");
                    }

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created a new account with password.");

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                        await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                        await _signInManager.SignInAsync(user, isPersistent : false);

                        _logger.LogInformation("User created a new account with password.");
                        return(RedirectToLocal(returnUrl));
                    }
                    AddErrors(result);
                }
                ModelState.AddModelError(model.Customercard, "User account already exists on this card number");
                return(View(model));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 3
0
        public IActionResult Index(RechargeAddModel model)
        {
            DateTime now = DateTime.Now;

            if (model.CardExpiry < now)
            {
                ModelState.AddModelError("CardExpiry", "Your Credit Card is Expire");
                return(View(model));
            }
            if (ModelState.IsValid)
            {
                var card    = GetCard(model.Customercard);
                var package = GetPackage(card.Package.Id);

                Recharge recharge = new Recharge()
                {
                    CardExpiry       = model.CardExpiry,
                    Cost             = model.Total,
                    CreditCardNumber = model.CreditCardNumber,
                    CVV          = model.CVV,
                    PaymentType  = model.PaymentType,
                    RechargeDate = now,
                    CustomerCard = card,
                    Package      = package
                };

                var cp = _cpService.GetByCardId(card.Id);
                cp.Status         = _statusService.GetByName("Charged");
                cp.ExpirationDate = now.AddMonths(model.Months);
                cp.NumberOfMonths = model.Months;
                cp.Package        = card.Package;
                cp.CustomerCard   = card;

                _cpService.Update(cp);
                _rechargeService.Add(recharge);

                ModelState.Clear();
                ViewBag.success = "success";
                ViewBag.msg     = "Your Account has been Recharge ,Thank You! for chossing our service";
                return(View());
            }

            return(View(model));
        }