Exemplo n.º 1
0
        public static long SetOrderDetails(DataBaseContext db, bool VIP = false, BankTransferModel BankTransfer = null, string Identity = null, long UserId = 0, string Currency = "EGP")
        {
            var customer_cart = _shopingCarts.Where(c => c.UserId == Identity).FirstOrDefault();

            if (customer_cart == null || customer_cart.CustomerInfo == null || customer_cart.CartItems == null || customer_cart.CartItems.Count < 1)
            {
                return(-1);
            }

            List <OrderItem> newOrderItems = new List <OrderItem>();
            decimal          TotalAmount   = 0;

            foreach (var orderItem in customer_cart.CartItems)
            {
                TotalAmount += (orderItem.NewPrice * orderItem.Quantity);
                newOrderItems.Add(new OrderItem()
                {
                    CarId      = orderItem.CarId,
                    Color      = orderItem.Color.Text,
                    Quantity   = (int)orderItem.Quantity,
                    Category   = orderItem.Category.Text,
                    IsDeleted  = false,
                    UnitPrice  = orderItem.NewPrice,
                    PaymenType = orderItem.PaymentType == 1?"Full Payment":"Down Payment"
                });
            }

            Order newOrder = new Order()
            {
                OrderDate   = DateTime.Now,
                OrderNumber = "S" + DateTime.Now.Day.ToString() + "I" + DateTime.Now.Month + "G" + DateTime.Now.Year.ToString().Substring(2, 2),
                OrderItems  = newOrderItems,
                TotalAmount = TotalAmount,
                Currency    = Currency,
                IsDeleted   = false,
                UserId      = UserId,
                Status      = "Pending"
            };

            customer_cart.Order = newOrder;



            customer_cart.CustomerInfo = db.Users.Where(s => s.Id == UserId).Select(u => new CustomerInfoModel
            {
                Individually    = u.Individually,
                FName           = u.FName,
                MName           = u.MName,
                LName           = u.LName,
                Phone           = u.Phone,
                DeliveryAddress = u.UserAddresses.Where(a => a.User.Id == UserId).FirstOrDefault().Address.DeliveryAddress,
                MainAddress     = u.UserAddresses.Where(a => a.User.Id == UserId).FirstOrDefault().Address.MainAddress

                                  //DeliveryAddress=u.UserAddresses,
            }).FirstOrDefault();
            db.Orders.Add(newOrder);
            // TODO: Send Mail Here
            if (VIP)
            {
                EmailTemplate Email     = new EmailTemplate();
                string        path      = @"~/Common/OrderDetailsEmailTemplate.html";
                var           emailHtml = Email.ReadTemplateEmail(customer_cart, path);
                GmailSender.SendEmail("*****@*****.**", "Serious!1", db.Mails.Select(s => s.mail).ToList(), "Order", emailHtml, null);
            }
            try
            {
                db.SaveChanges();
                BankTransferInfo bankTransferInfo = null;
                if (BankTransfer != null)
                {
                    bankTransferInfo = new BankTransferInfo()
                    {
                        ACH              = BankTransfer.ACH,
                        BBranch          = BankTransfer.BBranch,
                        BName            = BankTransfer.BName,
                        InputReferenceNo = BankTransfer.InputReferenceNo,
                        Memo             = BankTransfer.Memo,
                        PaymentDate      = BankTransfer.PaymentDate,
                        TransferNo       = BankTransfer.TransferNo,
                        OrderId          = newOrder.Id
                    };
                    db.BanksTransferInfo.Add(bankTransferInfo);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("error", ex);
            }


            return(newOrder.Id);
        }
Exemplo n.º 2
0
        public static long SetOrderDetails(string sessionId, DataBaseContext db, CreditCardModel creditCard = null, BankTransferModel BankTransfer = null)
        {
            var customer_cart = _shopingCarts.FirstOrDefault(cart => cart.SessionId == sessionId);

            if (customer_cart == null && customer_cart.CustomerInfo == null && customer_cart.CartItems == null && customer_cart.CartItems.Count < 1)
            {
                return(-1);
            }
            List <OrderItem> newOrderItems = new List <OrderItem>();

            foreach (var orderItem in customer_cart.CartItems)
            {
                newOrderItems.Add(new OrderItem()
                {
                    CarId    = orderItem.CarId,
                    Color    = orderItem.Color.Text,
                    Quantity = (int)orderItem.Quantity,
                    Category = orderItem.Category.Text,
                });
            }

            Order newOrder = new Order()
            {
                OrderDate   = DateTime.Now,
                OrderNumber = DateTime.Now.Day.ToString() + DateTime.Now.Month + DateTime.Now.Year,
                OrderItems  = newOrderItems
            };
            CardInfo card = null;

            if (creditCard != null)
            {
                card = new CardInfo()
                {
                    CardNumber      = creditCard.Number,
                    ExpiryDateMonth = creditCard.ExpiryDateMonth,
                    ExpiryDateYear  = creditCard.ExpiryDateYear,
                    CVCode          = creditCard.CVCode
                };
            }
            BankTransferInfo bankTransferInfo = null;

            if (BankTransfer != null)
            {
                bankTransferInfo = new BankTransferInfo()
                {
                    ACH              = BankTransfer.ACH,
                    BBranch          = BankTransfer.BBranch,
                    BName            = BankTransfer.BName,
                    InputReferenceNo = BankTransfer.InputReferenceNo,
                    Memo             = BankTransfer.Memo,
                    PaymentDate      = BankTransfer.PaymentDate,
                    TransferNo       = BankTransfer.TransferNo
                };
            }
            CorporateDetails corporateDetails = null;

            //CustomerDeliveryDetails Owner = new CustomerDeliveryDetails()
            //{
            //    Email = customer_cart.CustomerInfo.Email,
            //    Mobile = customer_cart.CustomerInfo.Phone,
            //    FirstName = customer_cart.CustomerInfo.FName,
            //    MiddleName = customer_cart.CustomerInfo.MName,
            //    LastName = customer_cart.CustomerInfo.LName,
            //    Address = customer_cart.CustomerInfo.MainAddress,
            //    DeliveryAddress = customer_cart.CustomerInfo.DeliveryAddress,
            //    City = customer_cart.CustomerInfo.City,
            //    Country = customer_cart.CustomerInfo.Country,
            //    Individually = customer_cart.CustomerInfo.Individually,
            //    PaymethodTypeId = 1,
            //    Zip = customer_cart.CustomerInfo.Zip,
            //    CardInfo = card,
            //    BankTransferInfo = bankTransferInfo

            //};

            //newOrder.DeliveryDetails = Owner;
            db.Orders.Add(newOrder);
            // TODO: Send Mail Here
            EmailTemplate Email     = new EmailTemplate();
            var           emailHtml = Email.ReadTemplateEmail(customer_cart);

            GmailSender.SendEmail("*****@*****.**", "Serious!1", "*****@*****.**", "Order", emailHtml, null);
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }
            if (customer_cart.CustomerInfo.Individually == 2)
            {
                corporateDetails = new CorporateDetails()
                {
                    CorporateName  = customer_cart.CustomerInfo.OrgnizationName,
                    CorporateSite  = customer_cart.CustomerInfo.OrgnizationSite,
                    RegistrationNo = customer_cart.CustomerInfo.RegistrationNo
                                     //Id = newOrder.DeliveryDetailsId
                };
                db.CorporatesDetails.Add(corporateDetails);
                db.SaveChanges();
            }

            return(newOrder.Id);
        }
Exemplo n.º 3
0
        public static void ChangeOrderStatus(DataBaseContext db, CarVendor.Web.Models.Order ROrder, string status)
        {
            Order order    = db.Orders.Where(c => c.Id == ROrder.id).FirstOrDefault();
            var   exchange = db.Conversions.Where(cc => cc.FromCurrency.Name == ROrder.currency).OrderByDescending(o => o.CreationDate).Select(s => s.Value).FirstOrDefault();

            switch (ROrder.currency)
            {
            case "USD":
                if (order.Currency == "USD" && order.TotalAmount == (decimal)ROrder.amount)
                {
                    order.Status = status;
                }
                else
                {
                    order.Status = "Different Amount";
                }

                break;

            case "EUR":
                if (order.Currency == "EUR" && order.TotalAmount == (decimal)ROrder.amount)
                {
                    order.Status = status;
                }
                else
                {
                    order.Status = "Different Amount";
                }
                break;

            default:
                if (order.Currency == "EGP" && order.TotalAmount == (decimal)ROrder.amount)
                {
                    order.Status = status;
                }
                else
                {
                    order.Status = "Different Amount";
                }
                break;
            }

            db.SaveChanges();
            CartModel customer_cart = new CartModel();

            customer_cart.Order     = order;
            customer_cart.CartItems = order.OrderItems.Select(s => new CartItemModel
            {
                Brand    = s.Car.Brand.Name,
                CarName  = s.Car.Name,
                Category = new CategoryModel {
                    Text = s.Category
                },
                Color = new ColorModel {
                    Text = s.Color
                },
                Price    = s.TotalPrice,
                Quantity = s.Quantity
            }).ToList();

            customer_cart.CustomerInfo = db.Users.Where(s => s.Id == order.UserId).Select(u => new CustomerInfoModel
            {
                Individually    = u.Individually,
                FName           = u.FName,
                MName           = u.MName,
                LName           = u.LName,
                Phone           = u.Phone,
                DeliveryAddress = u.UserAddresses.Where(a => a.User.Id == order.UserId).FirstOrDefault().Address.DeliveryAddress,
                MainAddress     = u.UserAddresses.Where(a => a.User.Id == order.UserId).FirstOrDefault().Address.MainAddress

                                  //DeliveryAddress=u.UserAddresses,
            }).FirstOrDefault();

            // TODO: Send Mail Here
            EmailTemplate Email     = new EmailTemplate();
            string        path      = @"~/Common/OrderDetailsEmailTemplate.html";
            var           emailHtml = Email.ReadTemplateEmail(customer_cart, path);
            var           Emails    = db.Mails.Select(s => s.mail).ToList();

            try
            {
                Emails.Add(order.User.Email);
                GmailSender.SendEmail("*****@*****.**", "Serious!1", Emails, "Order", emailHtml, null);
            }
            catch (Exception ex)
            {
                throw new Exception("error", ex);
            }
        }