public async Task <PreOrderViewModel> AddPreOrderAsync(PreOrderViewModel preOrder, CancellationToken ct = default(CancellationToken))
        {
            PreOrder newPreOrder = new PreOrder()
            {
                GearItemId = preOrder.GearItemId,
                Size       = preOrder.Size,
                Quantity   = preOrder.Quantity
            };

            newPreOrder = await _preOrderRepository.AddAsync(newPreOrder, ct);

            preOrder.Id = newPreOrder.Id;

            PreOrderContact newPreOrderContact = new PreOrderContact()
            {
                FirstName        = preOrder.Contact.FirstName,
                LastName         = preOrder.Contact.LastName,
                Email            = preOrder.Contact.Email,
                PhoneNumber      = preOrder.Contact.PhoneNumber,
                PreOrderId       = preOrder.Id,
                PreferredContact = preOrder.Contact.PreferredContact
            };

            preOrder.Contact = PreOrderContactConverter.Convert(await this._preOrderRepository.AddPreOrderContactAsync(newPreOrderContact, ct));

            return(preOrder);
        }
Пример #2
0
        public bool SendEmail(PreOrderViewModel email, GearItemViewModel gearItemPreOrder)
        {
            bool success = false;

            try
            {
                // Create the template class
                PreOrderTemplate preOrderTemplate = new PreOrderTemplate(this._configuration);

                // Message to User
                MimeMessage messageToUser = new MimeMessage();
                // Add From
                messageToUser.From.Add(new MailboxAddress(this._emailAppSettings[nameof(EmailServiceOptions.Admin)], this._emailAppSettings[nameof(EmailServiceOptions.AdminEmail)]));
                // Add TO
                messageToUser.To.Add(new MailboxAddress(User, email.Contact.Email));
                // Add Subject
                messageToUser.Subject = preOrderTemplate.SubjectForUser(gearItemPreOrder.Name);

                BodyBuilder bodyBuilderForUser = new BodyBuilder();

                bodyBuilderForUser.HtmlBody = preOrderTemplate.UserEmailBody(email, gearItemPreOrder);

                messageToUser.Body = bodyBuilderForUser.ToMessageBody();

                // Message To Admin
                MimeMessage messageToAdmin = new MimeMessage();
                // Add From
                messageToAdmin.From.Add(new MailboxAddress(this._emailAppSettings[nameof(EmailServiceOptions.Admin)], this._emailAppSettings[nameof(EmailServiceOptions.SystemAdminEmail)]));
                // Add TO
                messageToAdmin.To.Add(new MailboxAddress(this._emailAppSettings[nameof(EmailServiceOptions.Admin)], this._emailAppSettings[nameof(EmailServiceOptions.AdminEmail)]));
                // Add Subject
                messageToAdmin.Subject = preOrderTemplate.SubjectForAdmin(email.Id);

                BodyBuilder bodyBuilderForAdmin = new BodyBuilder();

                bodyBuilderForAdmin.HtmlBody = preOrderTemplate.AdminEmailBody(email, gearItemPreOrder);

                messageToAdmin.Body = bodyBuilderForAdmin.ToMessageBody();

                SmtpClient client = new SmtpClient();
                client.Connect(this._emailAppSettings[nameof(EmailServiceOptions.SmtpServer)], int.Parse(this._emailAppSettings[nameof(EmailServiceOptions.Port)]), true);
                client.Authenticate(this._emailAppSettings[nameof(EmailServiceOptions.SystemAdminEmail)], this._configuration[nameof(VaultKeys.SystemAdminEmailPassword)]);

                client.Send(messageToUser);
                client.Send(messageToAdmin);

                client.Disconnect(true);
                client.Dispose();

                success = true;
            }
            catch
            {
                success = false;
            }

            return(success);
        }
Пример #3
0
        public static PreOrderViewModel Convert(PreOrder preOrder)
        {
            PreOrderViewModel preOrderViewModel = new PreOrderViewModel();

            preOrderViewModel.Id         = preOrder.Id;
            preOrderViewModel.GearItemId = preOrder.GearItemId;
            preOrderViewModel.Quantity   = preOrder.Quantity;
            preOrderViewModel.Size       = preOrder.Size;
            preOrderViewModel.Contact    = PreOrderContactConverter.Convert(preOrder.Contact);

            return(preOrderViewModel);
        }
Пример #4
0
        public static List <PreOrderViewModel> ConvertList(IEnumerable <PreOrder> preOrders)
        {
            return(preOrders.Select(preOrder =>
            {
                PreOrderViewModel preOrderViewModel = new PreOrderViewModel();
                preOrderViewModel.Id = preOrder.Id;
                preOrderViewModel.GearItemId = preOrder.GearItemId;
                preOrderViewModel.Quantity = preOrder.Quantity;
                preOrderViewModel.Size = preOrder.Size;
                preOrderViewModel.Contact = PreOrderContactConverter.Convert(preOrder.Contact);

                return preOrderViewModel;
            }).ToList());
        }
        public PreOrderManageViewModel()
        {
            _context = new NitpickHouseDomainContext();

            _preordervm = new PreOrderViewModel(_context, null);
            _preordervm.EntityView.CurrentChanged += new EventHandler(EntityView_CurrentChanged);

            _preconsumerview = new CollectionViewSource();

            using (_preordervm.EntityView.DeferRefresh())
            {
                _preordervm.EntityView.PageSize = 20;
                _preordervm.EntityView.MoveToFirstPage();
            }
        }
Пример #6
0
        public string AdminEmailBody(PreOrderViewModel email, GearItemViewModel gearItem)
        {
            decimal total = Math.Round(email.Quantity.GetValueOrDefault() * gearItem.Price, 2);

            return($@"<html lang='en'>
<head>     
  <meta charset='utf-8'>
  <meta name='viewport' content='initial-scale=1, maximum-scale=1'>
  <meta name='viewport' content='width=device-width, initial-scale=1'>  
  <link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500' rel='stylesheet'>  
  <link href='https://fonts.googleapis.com/css?family=Roboto&display=swap' rel='stylesheet'>
  </style>
</head>
<body style='height: 100vh; font-family: 'Roboto', sans-serif; color:white; text-align: center'>   
    <div>            
        <img src='https://res.cloudinary.com/dwsvaiiox/image/upload/v1562171421/movies-place/itmfvw7fogexa8xqyzbg.png' style='max-width:100%; max-height:185px; margin: 0 auto; display: block'>
      </div>
    <div style='text-align: center'>
        <h3>Pre-order has been placed for {email.Quantity} {gearItem.Name}. The total is ${total}. Order Details:</h3>
    </div>
        <div style='margin-bottom: 10%'>
          <ul>
            <li>Item ID: {gearItem.Id}</li>
            <li>Size: {(Size)email.Size}</li>
            <li>Quantity: {email.Quantity}</li>
            <li>Price: ${Math.Round(gearItem.Price, 2)}</li>            
            <li>Name: {email.Contact.FirstName} {email.Contact.LastName}</li>
            <li>Phone Number: {email.Contact.PhoneNumber}</li>
            <li>E-Mail: {email.Contact.Email}</li>
            <li>Preferred Form of Contact: {(PreferredContact)email.Contact.PreferredContact}</li>            
          </ul>
        </div>
        <div>            
            <img src='{gearItem.Images[0].Url}' style='max-width:100%; max-height:250px; margin: 0 auto; display: block'>
          </div>
        <br>
        <div style='text-align: center; margin-bottom:15%'>
          
            <h4 style='font-weight: 900'>
                {_emailAppSettings[nameof(EmailServiceOptions.AdminEmail)]}
            </h4>
          <h4 style='font-weight: 900;'>
            {_emailAppSettings[nameof(EmailServiceOptions.AdminPhoneNumber)]}
          </h4>          
        </div>
</body>
</html>");
        }
Пример #7
0
        public async Task <IActionResult> OrderConfirm(int oid)
        {
            var orderRecord = await _context.OrderRecords
                              .SingleOrDefaultAsync(o => o.Id == oid && o.ShopId == Sid);

            var orderRecordDetails = await _context.OrderRecordDetails.Where(o => o.OrderId == oid).ToListAsync();

            var shop = await _context.Shops.SingleOrDefaultAsync(s => s.Id == orderRecord.ShopId);

            PreOrderViewModel model = new PreOrderViewModel
            {
                OrderRecord        = orderRecord,
                OrderRecordDetails = orderRecordDetails,
                Shop = shop
            };

            return(Json(model));
        }
        public async Task <ActionResult <PreOrderViewModel> > PreOrder(PreOrderViewModel preOrderForm, CancellationToken ct = default(CancellationToken))
        {
            GearItemViewModel gearItem = await this._supervisor.GetGearItemByIdAsync(preOrderForm.GearItemId);

            if (gearItem == null)
            {
                return(BadRequest(Errors.AddErrorToModelState(ErrorCodes.GearItemNotFound, ErrorDescriptions.GearItemFindFailure, ModelState)));
            }

            preOrderForm = await this._supervisor.AddPreOrderAsync(preOrderForm, ct);

            //Send an email out to let him know new pre-order has come in
            if (!this._emailService.SendEmail(preOrderForm, gearItem))
            {
                return(BadRequest(Errors.AddErrorToModelState(ErrorCodes.SendEmail, ErrorDescriptions.SendEmailFailure, ModelState)));
            }

            return(preOrderForm);
        }