Exemplo n.º 1
0
 /// <summary>
 /// getShippingCosts: get the shipping descriptions and fixed costs
 /// </summary>
 /// <param name="shippingCosts"></param>
 /// <returns></returns>
 public Boolean getShippingCosts(ShippingCostList shippingCosts)
 {
     shippingCosts.Clear();
     try{
         lock (_syncCall) {
             UniSubroutine s      = _sess.CreateUniSubroutine("u2_getShippingRates", 3);
             String        inData = String.Empty;
             if (_moneyFormat == 1)
             {
                 inData = "1";
             }
             s.SetArg(0, inData);
             s.Call();
             UniDynArray da      = s.GetArgDynArray(1);
             int         noTaxes = da.Dcount(2);
             for (int i = 1; i <= noTaxes; i++)
             {
                 ShippingCost sc = new ShippingCost();
                 sc.ShippingId  = da.Extract(1, i).StringValue;
                 sc.Description = da.Extract(2, i).StringValue;
                 sc.Cost        = Utils.safeDouble(da.Extract(3, i).StringValue);
                 shippingCosts.Add(sc);
             }
         }
     } catch (Exception ex) {
         ShowError(ex.Message);
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
        public void UpdateShippingCosts(UpdateShippingCostsRequest data)
        {
            using (var db = new Entities())
            {
                foreach (var country in data.Countries)
                {
                    foreach (var cost in country.ShippingCosts)
                    {
                        var shippingCost = db.ShippingCosts.SingleOrDefault(sc => sc.CountryId == country.Id && sc.ShippingCategoryId == cost.ShippingCategoryId);
                        if (shippingCost != null)
                        {
                            shippingCost.Amount           = cost.Amount;
                            shippingCost.AdditionalAmount = cost.AdditionalAmount;
                            db.Entry(shippingCost).State  = EntityState.Modified;
                        }
                        else
                        {
                            shippingCost = new ShippingCost
                            {
                                CountryId          = country.Id,
                                ShippingCategoryId = cost.ShippingCategoryId,
                                Amount             = cost.Amount,
                                AdditionalAmount   = cost.AdditionalAmount
                            };

                            db.ShippingCosts.Add(shippingCost);
                        }
                    }
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public ActionResult EditShippingCost(ShippingCost model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var shippingCost = _context.ShippingCosts.FirstOrDefault(s => s.Id == model.Id);

            shippingCost.City              = model.City;
            shippingCost.InCityCost        = model.InCityCost;
            shippingCost.IsInCityShipping  = model.IsInCityShipping;
            shippingCost.OutCityCost       = model.OutCityCost;
            shippingCost.IsOutCityShipping = model.IsOutCityShipping;
            shippingCost.IsInPerson        = model.IsInPerson;


            _context.SaveChanges();

            messageScreen.Typr    = "true";
            messageScreen.Content = "شكرا, تم تعديل التسعيره بنجاح";
            messageScreen.Action  = "Index";
            messageScreen.Control = "Product";
            return(RedirectToAction("Index", "Account", messageScreen));
        }
        public async Task <ActionResult> DeleteConfirmed(short id)
        {
            ShippingCost shippingCost = await db.ShippingCosts.FindAsync(id);

            db.ShippingCosts.Remove(shippingCost);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public IHttpActionResult Get(string zone, decimal weight)
        {
            ShippingCost rate = ShippingCosts.GetOne(zone, weight);

            if (rate == null)
            {
                return(NotFound());
            }
            return(Ok(rate));
        }
        public async Task <ActionResult> Edit([Bind(Include = "ShippingMethodId,CountryId,CostHalf,CostOne,CostOneHalf,CostTwo,CostTwoHalf")] ShippingCost shippingCost)
        {
            if (ModelState.IsValid)
            {
                db.Entry(shippingCost).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(shippingCost));
        }
        // GET: ShippingCosts/Edit/5
        public async Task <ActionResult> Edit(short?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShippingCost shippingCost = await db.ShippingCosts.FindAsync(id);

            if (shippingCost == null)
            {
                return(HttpNotFound());
            }
            return(View(shippingCost));
        }
Exemplo n.º 8
0
        public ActionResult AddShippingCost(ShippingCost model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _context.ShippingCosts.Add(model);
            _context.SaveChanges();

            messageScreen.Typr    = "true";
            messageScreen.Content = "شكرا, تم إكمال تسجيلك بنجاح";
            messageScreen.Action  = "Index";
            messageScreen.Control = "Product";
            return(RedirectToAction("Index", "Message", messageScreen));
        }
Exemplo n.º 9
0
        private void setShippingCosts(Entities db, string countryId, int shippingCategoryId, decimal amount, decimal additionalAmount)
        {
            var costs = db.ShippingCosts.SingleOrDefault(sc => sc.CountryId == countryId && sc.ShippingCategoryId == shippingCategoryId);

            if (costs == null)
            {
                costs = new ShippingCost
                {
                    CountryId          = countryId,
                    ShippingCategoryId = shippingCategoryId
                };
            }
            costs.Amount           = amount;
            costs.AdditionalAmount = additionalAmount;
            db.SaveChanges();
        }
Exemplo n.º 10
0
        // GET: Account/Create
        public ActionResult AddShippingCost()
        {
            string  userEmail     = authorizationManagement.IsUserLogedIn();
            Account currentUser   = _context.Accounts.FirstOrDefault(a => a.Email == userEmail);
            int     currentUserId = currentUser.Id;

            ShippingCost model = new ShippingCost()
            {
                AccountId         = currentUserId,
                InCityCost        = 0,
                OutCityCost       = 0,
                IsInPerson        = true,
                IsOutCityShipping = false,
                IsInCityShipping  = true,
            };

            return(View(model));
        }
Exemplo n.º 11
0
        // GET: ShoppingCart
        public ActionResult Index()
        {
            string  userEmail     = authorizationManagement.IsUserLogedIn();
            Account currentUser   = context.Accounts.FirstOrDefault(a => a.Email == userEmail);
            int     currentUserId = currentUser.Id;

            var shoppingCart = context.ShoppingCarts.Include("Product").Where(s => s.AccountId == currentUserId).ToList();

            Address address = context.Addresses.FirstOrDefault(a => a.AccountId == currentUserId);

            if (address == null)
            {
                return(RedirectToAction("AddAddress", "Account", null));
            }

            Cart cart = new Cart();

            int?storeId = 0;

            double?ItemsTotal    = 0;
            double?ShippingTotal = 0;

            foreach (var shoppingCa in shoppingCart.ToList())
            {
                storeId = shoppingCa.Product.AccountId;

                ShippingCost sC       = context.ShippingCosts.FirstOrDefault(s => s.AccountId == storeId);
                Account      accountt = context.Accounts.FirstOrDefault(a => a.Id == storeId);

                bool   canBeShippedTo = false;
                double shippingCost   = 0;

                if (address.City == sC.City && sC.IsInCityShipping == true)
                {
                    canBeShippedTo = true;
                    shippingCost   = sC.InCityCost;
                }

                if (address.City != sC.City && sC.IsOutCityShipping == true)
                {
                    canBeShippedTo = true;
                    shippingCost   = sC.OutCityCost;
                }

                ProductBySeller bySeller = new ProductBySeller()
                {
                    AccountId    = storeId,
                    CanBeShipped = canBeShippedTo,
                    ShippingCost = shippingCost,
                    Account      = accountt
                };

                foreach (var sCa in shoppingCart.Where(s => s.Product.AccountId == storeId).ToList())
                {
                    double?itemsTotal = 0;

                    var prod = sCa.Product;

                    double?productRealPrice = prod.Price;

                    if (prod.DiscountPercentage != null && prod.DiscountPercentage != 0)
                    {
                        productRealPrice = productRealPrice - (productRealPrice * prod.DiscountPercentage / 100);
                    }

                    productRealPrice = productRealPrice * sCa.Qty;

                    itemsTotal = itemsTotal + productRealPrice;

                    if (canBeShippedTo == true)
                    {
                        ItemsTotal = ItemsTotal + productRealPrice;
                    }


                    bySeller.Products.Add(sCa);

                    shoppingCart.Remove(sCa);
                }

                if (bySeller.Products.Count() > 0)
                {
                    ShippingTotal = ShippingTotal + shippingCost;
                    cart.ProductBySellers.Add(bySeller);
                }
            }

            cart.ItemsTotal    = ItemsTotal;
            cart.ShippingTotal = ShippingTotal;
            cart.VATTotal      = ItemsTotal * 0.05;
            cart.Total         = cart.VATTotal + ItemsTotal + cart.ShippingTotal;
            cart.Address       = address;

            return(View(cart));
        }
Exemplo n.º 12
0
        public ActionResult ConfirmOrder()
        {
            string  userEmail     = authorizationManagement.IsUserLogedIn();
            Account currentUser   = context.Accounts.FirstOrDefault(a => a.Email == userEmail);
            int     currentUserId = currentUser.Id;

            var orderLines = new List <OrderLine>();

            var shoppingCart = context.ShoppingCarts.Include("Product").Where(s => s.AccountId == currentUserId).ToList();

            Address address = context.Addresses.FirstOrDefault(a => a.AccountId == currentUserId);

            if (address == null)
            {
                return(RedirectToAction("AddAddress", "Account", null));
            }

            Cart cart = new Cart();

            int?storeId = 0;

            double?ItemsTotal    = 0;
            double?ShippingTotal = 0;

            foreach (var shoppingCa in shoppingCart.ToList())
            {
                storeId = shoppingCa.Product.AccountId;

                ShippingCost sC       = context.ShippingCosts.FirstOrDefault(s => s.AccountId == storeId);
                Account      accountt = context.Accounts.FirstOrDefault(a => a.Id == storeId);

                bool   canBeShippedTo = false;
                double shippingCost   = 0;
                double?totalForStore  = 0;

                if (address.City == sC.City && sC.IsInCityShipping == true)
                {
                    canBeShippedTo = true;
                    shippingCost   = sC.InCityCost;
                }

                if (address.City != sC.City && sC.IsOutCityShipping == true)
                {
                    canBeShippedTo = true;
                    shippingCost   = sC.OutCityCost;
                }

                ProductBySeller bySeller = new ProductBySeller()
                {
                    AccountId    = storeId,
                    CanBeShipped = canBeShippedTo,
                    ShippingCost = shippingCost,
                    Account      = accountt
                };

                foreach (var sCa in shoppingCart.Where(s => s.Product.AccountId == storeId).ToList())
                {
                    double?itemsTotal = 0;

                    var prod = sCa.Product;

                    double?productRealPrice = prod.Price;

                    if (prod.DiscountPercentage != null && prod.DiscountPercentage != 0)
                    {
                        productRealPrice = productRealPrice - (productRealPrice * prod.DiscountPercentage / 100);
                    }

                    var productSinglePrice = productRealPrice;
                    productRealPrice = productRealPrice * sCa.Qty;

                    itemsTotal = itemsTotal + productRealPrice;

                    if (canBeShippedTo == true)
                    {
                        OrderLine orderline = new OrderLine()
                        {
                            ProductId = sCa.Product.Id,
                            Qyt       = sCa.Qty
                        };

                        var reducedProduct = context.Products.FirstOrDefault(p => p.Id == prod.Id);

                        reducedProduct.Stock = reducedProduct.Stock - sCa.Qty;

                        context.SaveChanges();

                        orderline.ProductPrice = (productSinglePrice.HasValue) ? productSinglePrice.Value : 0;
                        orderline.TotalPrice   = (productRealPrice.HasValue) ? productRealPrice.Value : 0;
                        orderline.VatTotal     = ((productRealPrice * 0.05).HasValue) ? (productRealPrice * 0.05).Value : 0;
                        orderline.Total        = (((productRealPrice * 0.05) + productRealPrice).HasValue) ? ((productRealPrice * 0.05) + productRealPrice).Value : 0;

                        orderLines.Add(orderline);

                        totalForStore = totalForStore + productRealPrice;

                        ItemsTotal = ItemsTotal + productRealPrice;
                    }


                    bySeller.Products.Add(sCa);

                    shoppingCart.Remove(sCa);
                }

                if (bySeller.Products.Count() > 0)
                {
                    ShippingTotal = ShippingTotal + shippingCost;
                    cart.ProductBySellers.Add(bySeller);

                    if (bySeller.CanBeShipped == true)
                    {
                        var order = new Order();

                        order.SellerId      = storeId;
                        order.AccountId     = currentUserId;
                        order.ProductTotal  = (totalForStore.HasValue) ? totalForStore.Value : 0;
                        order.ServiceTotal  = (ShippingTotal.HasValue) ? ShippingTotal.Value : 0;
                        order.VatTotal      = ((totalForStore * 0.05).HasValue) ? (totalForStore * 0.05).Value : 0;
                        order.Total         = ((order.VatTotal + totalForStore + order.ServiceTotal).HasValue) ? (order.VatTotal + totalForStore + order.ServiceTotal).Value : 0;
                        order.City          = address.City;
                        order.Provice       = address.Provice;
                        order.Country       = address.Country;
                        order.AddressDtails = address.AddressDtails;
                        order.Status        = "جديد";
                        order.Number        = "OR" + DateTime.Now.Second.ToString() + Get8Digits();

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

                        var savedOrder = context.Orders.FirstOrDefault(o => o.Number == order.Number);

                        foreach (var ord in orderLines)
                        {
                            ord.OrderId = savedOrder.Id;
                            context.OrderLines.Add(ord);
                        }

                        context.SaveChanges();
                    }
                }
            }



            var inDbCart = context.ShoppingCarts.Where(s => s.AccountId == currentUserId).ToList();

            foreach (var sCart in inDbCart)
            {
                var willBeRemovedCart = context.ShoppingCarts.FirstOrDefault(s => s.Id == sCart.Id);
                context.ShoppingCarts.Remove(willBeRemovedCart);
            }

            context.SaveChanges();

            messageScreen.Typr    = "true";
            messageScreen.Content = "تم إنشاء طلبك بنجاح";
            messageScreen.Extra   = "الرجاء الذهاب لصفحة الطلبات الخاصة بك لمتابعة طلباتك";
            return(RedirectToAction("OrderConfirmation", "Message", messageScreen));
        }
        public void Test4()
        {
            var shippingCost = new ShippingCost();

            Assert.NotNull(shippingCost);
        }
Exemplo n.º 14
0
        public void GetOne_BadZone()
        {
            ShippingCost rate = ShippingCosts.GetOne("5", 2.0m);

            Assert.IsNull(rate);
        }
Exemplo n.º 15
0
        public void GetOne_GoodZone_WeightInRangeLowEdge()
        {
            ShippingCost rate = ShippingCosts.GetOne("4", 0.01m);

            Assert.IsTrue(rate.Cost == 1.25m);
        }
Exemplo n.º 16
0
        public void GetOne_GoodZone_WeightInRangeHighEdge()
        {
            ShippingCost rate = ShippingCosts.GetOne("3", 1.5m);

            Assert.IsTrue(rate.Cost == 2.25m);
        }
Exemplo n.º 17
0
        public void GetOne_GoodZone_WeightOutOfRangeLowEdge()
        {
            ShippingCost rate = ShippingCosts.GetOne("4", 2.01m);

            Assert.IsNull(rate);
        }