Exemple #1
0
        public ActionResult OrderShipped(string id, string trackingNumber)
        {
            var order = or.SelectById(id);

            if (order != null && trackingNumber != null)
            {
                order.TrackingNumber = trackingNumber;
                order.OrderStatus    = osr.SelectAll().FirstOrDefault(i => i.Status == "Kargoya Verildi");
                or.AddOrUpdate(order);

                //SmtpClient smtp = new SmtpClient();
                //smtp.Port = 587;
                //smtp.Host = "smtp.office365.com";
                //smtp.EnableSsl = true;
                //smtp.Credentials = new NetworkCredential("*****@*****.**", "project321");

                //MailMessage mail = new MailMessage();
                //mail.From = new MailAddress("*****@*****.**", "E-Commerce Project");
                //mail.To.Add(order.User.Email);
                //mail.Subject = "Siparişiniz Kargoya Verilmiştir.";
                //mail.IsBodyHtml = true;
                //mail.Body = order.Id.Replace("-", "").ToUpper() + " Takip numaralı siparişiniz kargoya verilmiştir. <br /> Kargo Firması: " + order.Shipping.Name + "<br /> Takip No: " + order.TrackingNumber;
                //smtp.Send(mail);
            }
            return(RedirectToAction("OrderList"));
        }
        public ActionResult OrderCompleted(int ShipperId)
        {
            var cart = (CartModel)Session["Cart"];

            if (cart == null)
            {
                return(RedirectToAction("TimeOut"));
            }

            var order = new Order();

            order.ShipperId = ShipperId;
            order.UserId    = ur.SelectAll().FirstOrDefault(i => i.Username == User.Identity.Name).Id;
            foreach (var item in cart.CartLine)
            {
                var orderDetail = new OrderDetail();
                orderDetail.ProductId = item.ProductId;
                orderDetail.Quantity  = item.Quantity;
                orderDetail.UnitPrice = item.SubTotal;
                order.OrderDetails.Add(orderDetail);
            }
            if (or.AddOrUpdate(order))
            {
                foreach (var orderDetail in order.OrderDetails)
                {
                    var product = pr.SelectById(orderDetail.ProductId);
                    product.Stock -= Convert.ToInt16(orderDetail.Quantity);
                    pr.AddOrUpdate(product);
                }
                Session["Order"] = order;
                return(RedirectToAction("OrderInfo"));
            }
            return(RedirectToAction("OrderNotCreated"));
        }
Exemple #3
0
        public ActionResult OrderStatus(int id)
        {
            var order = or.SelectById(id);

            if (order != null)
            {
                order.OrderStatus = true;
                or.AddOrUpdate(order);
            }
            return(RedirectToAction("List"));
        }
Exemple #4
0
        public ActionResult OrderIsOk()
        {
            if ((Order)Session["Order"] == null)
            {
                return(RedirectToAction("TimeOut"));
            }
            var order = (Order)Session["Order"];
            var or    = new OrderRepository();

            if (or.AddOrUpdate(order))
            {
                var pr = new ProductRepository();

                foreach (var orderDetails in order.OrderDetails)
                {
                    var product = pr.SelectById(orderDetails.ProductId);
                    product.Stock -= orderDetails.Quantity;
                    pr.AddOrUpdate(product);
                }

                Session["Cart"] = new Cart();
                var userStore   = new UserStore <User>(DbInstance.Instance);
                var userManager = new UserManager <User>(userStore);
                var user        = userManager.FindByName(User.Identity.Name);
                ViewBag.UserEmail = user.Email;

                //SmtpClient smtp = new SmtpClient();
                //smtp.Port = 587;
                //smtp.Host = "smtp.office365.com";
                //smtp.EnableSsl = true;
                //smtp.Credentials = new NetworkCredential("*****@*****.**", "project321");

                //MailMessage mail = new MailMessage();
                //mail.From = new MailAddress("*****@*****.**", "E-Commerce Project");
                //mail.To.Add(user.Email);
                //mail.Subject = "Siparişiniz Hk.";
                //mail.IsBodyHtml = true;
                //mail.Body = _OrderMailBody().PartialRenderToString(); ;
                //smtp.Send(mail);

                return(View());
            }
            else
            {
                return(View("Error"));
            }
        }
        public async Task Consume(ConsumeContext <IOrderProductRequested> context)
        {
            if (context.Message.Products == null)
            {
                throw new Exception("Product cannot be null");
            }

            Order order = (Order)context.Message.Order;

            if (context.Message.Order != null)
            {
                order = _orderRepository.GetByID(context.Message.Order.OrderId);
                _orderProductRepository.RemoveByOrderId(context.Message.Order.OrderId);
            }

            order = new Order()
            {
                StatusCode     = StatusCode.Waiting,
                IsDeleted      = false,
                CreatedDate    = DateTime.UtcNow,
                ItemTotalPrice = context.Message.Products.Sum(l => l.PricePerUnit)
            };

            _orderRepository.AddOrUpdate(order);

            var orderProductList = context.Message.Products.GroupBy(l => l.ProductId)
                                   .Select(cl => new OrderProduct {
                OrderId     = order.OrderId,
                ProductId   = cl.First().ProductId,
                ProductName = cl.First().Name,
                Quantity    = cl.Count(),
                TotalPrice  = cl.Sum(c => c.PricePerUnit),
                IsDeleted   = false
            }).ToList();

            _orderProductRepository.AddOrUpdateAll(orderProductList);

            _orderProductRepository.Save();

            await context.Publish <IOrderApproveRequest>(new { Order = order });

            Console.WriteLine("Order requested successfully.");
            //return Task.CompletedTask;
        }
Exemple #6
0
        public Task Consume(ConsumeContext <IOrderAccepted> context)
        {
            //Decrease or increase quantity of product stock numbers randomly
            RandomStockChange();

            Order order = _orderRepository.GetByID(context.Message.Order.OrderId);

            if (order == null)
            {
                Console.WriteLine("Order failed.");
                throw new Exception("Order Failed");
            }

            order.StatusCode   = StatusCode.Accepted;
            order.IsDeleted    = false;
            order.ModifiedDate = DateTime.UtcNow;

            _orderRepository.AddOrUpdate(order);

            var products = new List <Product>();

            foreach (var orderProduct in context.Message.OrderProducts.Where(x => x.OrderId == order.OrderId))
            {
                var product = _productRepository.GetAll().FirstOrDefault(x => x.ProductId == orderProduct.ProductId);
                //Decrease stock number
                product.InStock = product.InStock - orderProduct.Quantity;
                products.Add(product);
            }

            _productRepository.AddOrUpdateAll(products);

            _productRepository.Save();
            _orderRepository.Save();

            Console.WriteLine("Order accepted.");
            Console.WriteLine($"OrderID: {order.OrderId} -> Order Status: {order.StatusCode.ToString()} | Total Price: {order.ItemTotalPrice:C}");

            return(Task.CompletedTask);
        }