Ejemplo n.º 1
0
        public int CreateNewOrderAndDetails(ProductDetailPostViewModel productDetailView, Product product, HttpPostedFileBase fileUpload)
        {
            Order order = new Order();

            order.Id                = Guid.NewGuid();
            order.IsDelete          = false;
            order.IsPaid            = false;
            order.SubmitDate        = DateTime.Now;
            order.Code              = codeCreator.ReturnOrderCode();
            order.DeliverEmail      = productDetailView.Email;
            order.DeliverCellNumber = productDetailView.CellNumber;
            order.DeliverFullName   = productDetailView.FirstName + "-" + productDetailView.LastName;
            order.IsFinal           = false;



            decimal subTotal = product.Amount;

            order.TotalAmount = subTotal;


            db.Orders.Add(order);

            CreateNewOrderDetail(order.Id, productDetailView, product, fileUpload);

            return(order.Code);
        }
Ejemplo n.º 2
0
        public Order ConvertCoockieToOrder(List <ProductInCart> products, string cellnumber, string email, string fullname)
        {
            try
            {
                CodeCreator codeCreator = new CodeCreator();

                Order order = new Order();

                order.Id                = Guid.NewGuid();
                order.IsDelete          = false;
                order.IsPaid            = false;
                order.SubmitDate        = DateTime.Now;
                order.Code              = codeCreator.ReturnOrderCode();
                order.DeliverEmail      = email;
                order.DeliverCellNumber = cellnumber;
                order.DeliverFullName   = fullname;

                decimal subTotal = GetSubtotal(products);
                order.TotalAmount = subTotal;


                db.Orders.Add(order);
                db.SaveChanges();



                foreach (ProductInCart product in products)
                {
                    decimal amount = product.Product.Amount;



                    OrderDetail orderDetail = new OrderDetail()
                    {
                        Id         = Guid.NewGuid(),
                        ProductId  = product.Product.Id,
                        Quantity   = product.Quantity,
                        RowAmount  = amount * product.Quantity,
                        IsDelete   = false,
                        SubmitDate = DateTime.Now,
                        OrderId    = order.Id,
                        Amount     = amount
                    };

                    db.OrderDetails.Add(orderDetail);
                    db.SaveChanges();
                }

                return(order);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public Order ConvertCoockieToOrder(List <ProductInCart> products)
        {
            try
            {
                Order order = new Order();

                order.Id               = Guid.NewGuid();
                order.IsActive         = true;
                order.IsDeleted        = false;
                order.IsPaid           = false;
                order.CreationDate     = DateTime.Now;
                order.LastModifiedDate = DateTime.Now;
                order.Code             = codeCreator.ReturnOrderCode();
                order.OrderStatusId    = db.OrderStatuses.FirstOrDefault(current => current.Code == 1).Id;
                order.SubTotal         = GetSubtotal(products);



                //order.DiscountAmount = GetDiscount();
                //order.DiscountCodeId = GetDiscountId();

                //order.TotalAmount = Convert.ToDecimal(order.SubTotal - order.DiscountAmount);


                db.Orders.Add(order);

                foreach (ProductInCart product in products)
                {
                    decimal     amount      = GetAmountByProductForInsertOrderDetail(product.Product);
                    OrderDetail orderDetail = new OrderDetail()
                    {
                        ProductId           = product.Product.Id,
                        Quantity            = product.Quantity,
                        Amount              = amount * product.Quantity,
                        IsDeleted           = false,
                        IsActive            = true,
                        CreationDate        = DateTime.Now,
                        OrderId             = order.Id,
                        Price               = amount,
                        OrderDetailStatusId = db.OrderDetailStatuses.FirstOrDefault(current => current.Code == 1).Id
                    };


                    db.OrderDetails.Add(orderDetail);
                }

                return(order);
            }
            catch (Exception e)
            {
                return(null);
            }
        }