private int AddCartHeader(CartHeader cartHeader, POSInventoryContext context)
        {
            Cart_Header cHeader = new Cart_Header
                {
                    dateadded = DateTime.Now,
                    agentID = cartHeader.AgentID,
                    merchant_fk = cartHeader.MerchantId,
                    order_total = cartHeader.Total,
                    order_tax = cartHeader.Tax,
                    order_discount = cartHeader.Discount,
                    order_net = cartHeader.Net,
                    orShipTo = cartHeader.ShippingInfo.To,
                    orShipAddress1 = cartHeader.ShippingInfo.AddressOne,
                    orShipAddress2 = cartHeader.ShippingInfo.AddressTwo,
                    orShipCity = cartHeader.ShippingInfo.City,
                    orShipState = cartHeader.ShippingInfo.State,
                    orShipZipCode = cartHeader.ShippingInfo.ZipCode,
                    orShipCountry = cartHeader.ShippingInfo.Country,
                    orShipPhone = cartHeader.ShippingInfo.Phone,
                    orRefNotes = cartHeader.ShippingInfo.Notes,
                    FedExHomeDelivery = cartHeader.ShippingInfo.FedExHomeDelivery,
                    FedExSaturdayDelivery = cartHeader.ShippingInfo.FedExSaturdayDelivery,
                    orShipCost = cartHeader.ShippingInfo.Cost,
                    orShipEmail = cartHeader.ShippingInfo.Email,
                    orTotalWeight = cartHeader.TotalWeight,
                    orWeight_measureID = cartHeader.WeightId,
                    deploymethID = cartHeader.DeploymentId,
                };

            int cHeaderId = context.InsertCartHeader(cHeader);

            return cHeaderId;
        }
        private void AddCartDetails(CartHeader cartHeader, int cHeaderId, POSInventoryContext context)
        {
            foreach (var cartItem in cartHeader.Items)
            {
                Cart_Detail cDetail = new Cart_Detail
                    {
                        cart_id = cHeaderId,
                        thType = cartItem.Type,
                        thingID = cartItem.Id,
                        description = cartItem.Description,
                        qty = cartItem.Quantity,
                        price = cartItem.Price,
                        extended = cartItem.Extended,
                        discount = cartItem.Discount,
                        tax = cartItem.Tax,
                        unit = cartItem.Unit,
                        weight = cartItem.Weight,
                        weight_measureID = cartItem.WeightId
                    };

                context.InsertCartDetails(cDetail);
            }

            context.SaveChanges();
        }
Пример #3
0
 private User GetUserFromCart(CartHeader cart)
 {
     if (cart.AgentID != 0)
     {
         return _userRepository.Get(user => user.RefId == cart.AgentID).FirstOrDefault();
     }
     else
     {
         return _userRepository.Get(user => user.RefId == cart.MerchantId).FirstOrDefault();
     }
 }
Пример #4
0
        public int AddOrder(CartHeader cart)
        {
            int inventoryOrderId = _inventoryRepository.CreateOrderFrom(cart);
            User user = GetUserFromCart(cart);
            Order order = new Order
                {
                    UserId = user.Id,
                    RefId = inventoryOrderId
                };

            _orderRepository.Add(order);
            _unitOfWork.Commit();

            return order.Id;
        }
        public int CreateOrderFrom(CartHeader cartHeader)
        {
            try
            {
                using (POSInventoryContext context = new POSInventoryContext())
                {
                    int cHeaderId = AddCartHeader(cartHeader, context);
                    AddCartDetails(cartHeader, cHeaderId, context);

                    var orderId = AddOrder(cartHeader, context, cHeaderId);

                    return orderId;
                }
            }
            catch (Exception e)
            {
                throw new DataAccessException("Error POSInventoryContext access", e);
            }
        }
 private int AddOrder(CartHeader cartHeader, POSInventoryContext context, int cHeaderId)
 {
     int orderId = context.InsertOrder(
         cHeaderId,
         cartHeader.AgentID,
         cartHeader.DeploymentId,
         0,
         cartHeader.ShippingInfo.To,
         cartHeader.ShippingInfo.AddressOne,
         cartHeader.ShippingInfo.AddressTwo,
         cartHeader.ShippingInfo.City,
         cartHeader.ShippingInfo.State,
         cartHeader.ShippingInfo.ZipCode,
         cartHeader.ShippingInfo.Country,
         cartHeader.ShippingInfo.Phone,
         cartHeader.Tax,
         cartHeader.Discount,
         cartHeader.Net,
         cartHeader.ShippingInfo.FedExHomeDelivery,
         cartHeader.ShippingInfo.FedExSaturdayDelivery,
         cartHeader.ShippingInfo.Email
         );
     return orderId;
 }
Пример #7
0
        private CartHeader GetOrderReady(IEnumerable<MarketingProduct> marketingMaterials)
        {
            try
            {
                var userLogged = Session[Utils.UserKey] as UserModel;

                var shippingInfo = new ShippingInfo
                {
                    AddressOne = userLogged.Address1,
                    AddressTwo = userLogged.Address2,
                    City = userLogged.City,
                    Cost = 15,
                    Country = "USA",
                    Email = userLogged.Email,
                    Phone = userLogged.Phone,
                    State = userLogged.State,
                    ZipCode = userLogged.ZipCode,
                    To = userLogged.Name
                };

                var cartDetails = marketingMaterials.Select(thing => new CartItem
                {
                    Description = thing.Name,
                    Price = thing.Price.IsNull() ? 0 : thing.Price.Value,
                    Discount = thing.Discount.IsNull() ? 0 : thing.Discount.Value,
                    Weight = thing.Weight.IsNull() ? 0 : thing.Weight.Value,
                    Quantity = thing.Quantity,
                    Extended = marketingMaterials.Sum(item => item.Price).Value,
                    Tax = 0,
                    Type = thing.thType.ToString(),
                    Unit = "Units",
                    WeightId = thing.Weight_measureID.Value,
                    Id = thing.thingID.Value
                });

                var isAnAgent = Utils.IsUserAgent(userLogged.UserCategory);

                var cartHeader = new CartHeader
                {
                    AgentID = isAnAgent ? userLogged.UserId : 0,
                    Items = cartDetails.ToList(),
                    ShippingInfo = shippingInfo,
                    TotalWeight = cartDetails.Sum(item => (item.Weight*item.Quantity)),
                    Total = cartDetails.Sum(item => (item.Price*item.Quantity)) + shippingInfo.Cost,
                    MerchantId = isAnAgent ? 0 : userLogged.UserId,
                };

                return cartHeader;

            }
            catch (Exception exception)
            {
                return null;
            }
        }