Ejemplo n.º 1
0
        public async Task <IActionResult> AddEmail(string email)
        {
            MailAddress emailAddress;

            try
            {
                emailAddress = getAddress(email);
                logger.LogInformation($"Email {emailAddress.Address} added to list");

                var emailCheck = await emailSubscriptions.FindAsync(x => x.Email.Equals(emailAddress.Address));

                if (emailCheck == null)
                {
                    emailCheck = new EmailSubscription()
                    {
                        Email  = emailAddress.Address,
                        Status = true
                    };
                    await emailSubscriptions.AddAsync(emailCheck);
                }
                else if (!emailCheck.Status)
                {
                    emailCheck.Status = true;
                    await emailSubscriptions.UpdateAsync(emailCheck);
                }
                modalNotification.AddNotificationSweet("Email", NotificationType.success, "You subscribed to the list!");
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }
            catch
            {
                logger.LogInformation($"Failed adding email to list");
                modalNotification.AddNotificationSweet("Fail", NotificationType.error, "Please check your email!");
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }
        }
        public async Task <IActionResult> Delete(int id)
        {
            Invoice invoice = invoices.GetIncluding(x => x.InvoiceId == id,
                                                    x => x.InvoicesInfo)
                              .First();

            invoice.Status = EnumStatus.Cancelled;

            try
            {
                var result = await invoices.UpdateAsync(invoice);

                logger.LogInformation($"Invoice {id} cancelled");
            }
            catch (Exception ex)
            {
                logger.LogInformation(ex.Message);
                modalNotification.AddNotificationSweet("Invoice" + id.ToString(), NotificationType.warning, "Not cancelled!");
            }

            Tube tempTube;

            foreach (var item in invoice.InvoicesInfo)
            {
                tempTube = await tubes.GetAsync(item.TubeId);

                tempTube.Quantity += item.Quantity;
                await tubes.UpdateAsync(tempTube);

                logger.LogInformation($"Tube {tempTube.TubeId} returned {item.Quantity} to stock.");
            }

            modalNotification.AddNotificationSweet("Invoice" + id.ToString(), NotificationType.success, "Invoice cancelled!");

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Add(int tubeId)
        {
            string userId = userManager.GetUserId(User);

            Watchlist watchlist = new Watchlist()
            {
                TubeId     = tubeId,
                CustomerId = userId
            };

            try
            {
                var watchResult = await watchlists.AddAsync(watchlist);
            }
            catch (Exception ex)
            {
                logger.LogInformation(ex.Message);
                logger.LogInformation($"Failed adding tube to watchlist");
                modalNotification.AddNotificationSweet("Fail", NotificationType.error, "Please try later!");
            }

            modalNotification.AddNotificationSweet("Watchlist", NotificationType.success, "The tube has been added to your watchlist.");
            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Checkout()
        {
            Customer customer = await userManager.GetUserAsync(User);

            if (customer == null)
            {
                logger.LogInformation($"Checkout failed");
                modalNotification.AddNotificationSweet("Fail", NotificationType.error, "Please try later!");
                return(RedirectToAction(nameof(ReturnCart)));
            }

            ShippingAddress billingAddress = new ShippingAddress()
            {
                AddressLine1 = customer.AddressLine1,
                AddressLine2 = customer.AddressLine2,
                ZipCode      = customer.ZipCode,
                City         = customer.City,
                State        = customer.State,
                Country      = customer.Country
            };

            ShippingAddress shippingAddress = await shippingAddresses.FindAsync(
                x => x.CustomerId.Equals(customer.Id)) ?? new ShippingAddress();

            CheckoutViewModel model = new CheckoutViewModel();

            model.BillingAddress  = billingAddress;
            model.ShippingAddress = shippingAddress;
            model.Customer        = new CustomerViewModel()
            {
                CustomerId = customer.Id,
                FirstName  = customer.FirstName,
                LastName   = customer.LastName,
                Email      = customer.Email,
                Phone      = customer.PhoneNumber
            };

            return(View(model));
        }