예제 #1
0
        public static void SendCheckoutEmail(User user, Basket basket, DeliveryInformation deliveryInformation)
        {
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials           = new NetworkCredential("*****@*****.**", "HZsxgU3F"),
                EnableSsl             = true,
                UseDefaultCredentials = false,
            };

            var body = CheckoutContent
                       .Replace("$products",
                                string.Concat(basket.Products.Select(
                                                  x => ProductEntryBody
                                                  .Replace("$title", x.Product.Name)
                                                  .Replace("$image", "https://prochoc.tk/" + x.Product.Picture)
                                                  .Replace("$stk", x.Count.ToString())
                                                  .Replace("$price", "€ " + (x.Count * float.Parse(x.Product.Price, CultureInfo.InvariantCulture)))
                                                  )
                                              )
                                )
                       .Replace("$basketId", basket.Id.ToString());

            var message = new MailMessage(
                "*****@*****.**",
                user.Email,
                "Prochoc Account Bestätigung",
                body);

            message.IsBodyHtml = true;
            client.Send(message);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            DeliveryInformation deliveryInformation = db.DeliveryInformations.Find(id);

            db.DeliveryInformations.Remove(deliveryInformation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "DeliveryInformationID,OrderID,DeliverymansID,Signature")] DeliveryInformation deliveryInformation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(deliveryInformation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DeliverymansID = new SelectList(db.Deliverymen, "DeliverymansID", "DeliverymanName", deliveryInformation.DeliverymansID);
     ViewBag.OrderID        = new SelectList(db.Orders, "OrderID", "DeliveryTime", deliveryInformation.OrderID);
     return(View(deliveryInformation));
 }
        // GET: DeliveryInformations/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DeliveryInformation deliveryInformation = db.DeliveryInformations.Find(id);

            if (deliveryInformation == null)
            {
                return(HttpNotFound());
            }
            return(View(deliveryInformation));
        }
        // GET: DeliveryInformations/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DeliveryInformation deliveryInformation = db.DeliveryInformations.Find(id);

            if (deliveryInformation == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DeliverymansID = new SelectList(db.Deliverymen, "DeliverymansID", "DeliverymanName", deliveryInformation.DeliverymansID);
            ViewBag.OrderID        = new SelectList(db.Orders, "OrderID", "DeliveryTime", deliveryInformation.OrderID);
            return(View(deliveryInformation));
        }
예제 #6
0
        private object DoSwitchStore(string deliveryType, string deliveryAddress, Store storeToSwitchTo,
                                     bool nullCart, bool nullDeliveryInfo)
        {
            var deliveryInfo = new DeliveryInformation(deliveryType, _nordstan, 60)
            {
                DeliveryAddress = deliveryAddress
            };

            if (nullDeliveryInfo)
            {
                deliveryInfo = null;
                // if deliveryInfo is null then address is meaningless so skip this combination in the tests
                if (deliveryAddress != null)
                {
                    return(null);
                }
            }

            Cart cart = new Cart();

            cart.AddItem(_cherryBloom);
            cart.AddItem(_blusherBrush);
            cart.AddItem(_masterclass);
            cart.AddItem(_makeoverNordstan);
            if (nullCart)
            {
                cart = null;
                if (deliveryInfo != null)
                {
                    return(null);
                }
            }

            Session session = new NonSavingSession();

            session.Put("STORE", _nordstan);
            session.Put("DELIVERY_INFO", deliveryInfo);
            session.Put("CART", cart);
            var shopping = new OnlineShopping(session);

            shopping.SwitchStore(storeToSwitchTo);
            return(shopping.ToString());
        }
예제 #7
0
 public ProviderDocument CreateFrameworkProviderDocument(CoreProvider provider, FrameworkInformation frameworkInformation, DeliveryInformation deliveryInformation)
 {
     return(CreateFrameworkProviderDocument(provider, frameworkInformation, new List <DeliveryInformation> {
         deliveryInformation
     }));
 }
예제 #8
0
 public ProviderDocument CreateStandardProviderDocument(CoreProvider provider, StandardInformation standardInformation, DeliveryInformation deliveryInformation)
 {
     return(CreateStandardProviderDocument(provider, standardInformation, new List <DeliveryInformation> {
         deliveryInformation
     }));
 }
예제 #9
0
 public record CheckoutRequestModel(PersonalInformation PersonalInformation, DeliveryInformation DeliveryInformation);
예제 #10
0
        public string PlaceOrder(string deliveryAddress)
        {
            if (ModelState.IsValid)
            {
                string email = HttpContext.User.Identity.Name;
                //create new delivery information
                DeliveryInformation deliveryInformation = new DeliveryInformation();
                CustomerViewModel   customer            = unitOfWork.CustomerRepository.Get(c => c.Email == email)
                                                          .Select(c => new CustomerViewModel {
                    Id          = c.Id,
                    Name        = c.Name,
                    Address     = c.Address,
                    BirthDate   = c.BirthDate,
                    Email       = c.Email,
                    PhoneNumber = c.PhoneNumber
                }).FirstOrDefault();
                deliveryInformation.Id              = Guid.NewGuid();
                deliveryInformation.PhoneNumber     = customer.PhoneNumber;
                deliveryInformation.ReceiverName    = customer.Name;
                deliveryInformation.DeliveryFee     = 0;
                deliveryInformation.DeliveryAddress = deliveryAddress;

                //create new order object
                Order order = new Order();
                order.Id = Guid.NewGuid();
                order.TotalPriceOrder = GetShoppingCart().CalculateTotalPrice();
                order.OrderStatusId   = 1;//admin not confirm yet
                order.CreatedDate     = DateTime.UtcNow;
                order.DeliveryDate    = DateTime.UtcNow.AddDays(3);
                order.DeliveryId      = deliveryInformation.Id;
                order.CustomerId      = customer.Id;

                //create new list of order detail objects
                List <OrderDetail> listOrderDetails = new List <OrderDetail>();
                foreach (CartItemViewModel cartItem in GetShoppingCart().CartItems)
                {
                    OrderDetail orderDetail = new OrderDetail();
                    orderDetail.Id            = Guid.NewGuid();
                    orderDetail.BookId        = cartItem.BookItem.Id;
                    orderDetail.OrderQuantity = cartItem.Quantity;
                    orderDetail.TotalPrice    = cartItem.BookItem.Price * cartItem.Quantity;
                    orderDetail.OrderId       = order.Id;
                    listOrderDetails.Add(orderDetail);
                }
                using (var transaction = unitOfWork.Context.Database.BeginTransaction())
                {
                    try
                    {
                        //save delivery information
                        unitOfWork.Context.DeliveryInformation.Add(deliveryInformation);
                        //save order
                        unitOfWork.Context.Order.Add(order);
                        foreach (var orderDetail in listOrderDetails)
                        {
                            //save order detail
                            unitOfWork.Context.OrderDetail.Add(orderDetail);
                            //update quantity book
                            var book = unitOfWork.BookRepository.GetById(orderDetail.BookId);
                            book.Quantity -= orderDetail.OrderQuantity;
                            unitOfWork.BookRepository.Update(book);
                        }

                        unitOfWork.Save();
                        transaction.Commit();
                        //clear shopping cart
                        Session["ShoppingCart"] = null;
                        return(Url.Action("Index", "Book"));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        unitOfWork.Dispose();
                        ViewBag.Error = "Error occur while saving data";
                        return("");
                    }
                }
            }
            return("");
        }