public static Models.Inventory GetInventory(int id, int?qty)
        {
            var result = new Models.Inventory();

            using (var ctx = new Data.AMEntDataContext())
            {
                result = ctx.Inventories
                         .Where(x => x.ID == id)
                         .Select(x => new Models.Inventory
                {
                    Id               = x.ID,
                    ItemCode         = x.ItemCode,
                    Description      = x.Remarks.Trim().Length > 0 ? x.Remarks : x.Description,
                    ShortDescription = x.ShortDescription,
                    UOfM             = x.UnitOfMeasure.UOMCode,
                    Quantity         = qty,
                    ListPrice        = x.InventoryPrices != null ?
                                       x.InventoryPrices.FirstOrDefault() != null ?
                                       x.InventoryPrices.FirstOrDefault().InventoryListPrices != null && x.InventoryPrices.FirstOrDefault().InventoryListPrices.Count() > 0 ?
                                       x.InventoryPrices.FirstOrDefault().InventoryListPrices.Max(a => a.ListPrice) : 0
                                : 0
                            : 0,
                    ImagePath = Resource.StaticResource.ImagePath
                }).SingleOrDefault();
            }

            return(result);
        }
Exemple #2
0
        public ActionResult Index(Models.Customer customer)
        {
            if (ModelState.IsValid)
            {
                //TODO login authentication and process

                bool isAuth = false;

                using (var ctx = new Data.AMEntDataContext())
                {
                    isAuth = ctx.Customers.Where(x => x.CustomerCode.ToLower() == customer.CustomerCode.ToLower()).Any();

                    if (isAuth)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Login"));
                    }
                }
            }

            return(View(customer));
        }
Exemple #3
0
        private static List <Models.ShoppingCart> GetShoppingCart()
        {
            int ctr = 0;

            var shoppingCart = new List <Models.ShoppingCart>();

            using (var ctx = new Data.AMEntDataContext())
            {
                foreach (var x in ctx.Inventories)
                {
                    if (ctr < 3)
                    {
                        var qty      = 1; //new Random().Next(1, 5);
                        var lstPrice = x.InventoryPrices != null?
                                       x.InventoryPrices.FirstOrDefault() != null?
                                       x.InventoryPrices.FirstOrDefault().InventoryListPrices != null && x.InventoryPrices.FirstOrDefault().InventoryListPrices.Count() > 0 ?
                                       x.InventoryPrices.FirstOrDefault().InventoryListPrices.Max(a => a.ListPrice) : 0
                                       : 0
                                       : 0;

                        var totalPrice = qty * lstPrice;

                        shoppingCart.Add(new Models.ShoppingCart()
                        {
                            CartId       = x.ID,
                            ProductCode  = x.ItemCode,
                            ProductName  = x.Description,
                            Size         = Resource.StaticResource.Size[new Random().Next(0, 2)],
                            Color        = Resource.StaticResource.Color[new Random().Next(0, 4)],
                            Quantity     = qty,
                            CurrencyName = "USD",
                            ListPrice    = lstPrice,
                            TotalPrice   = totalPrice,
                            ImagePath    = Resource.StaticResource.ImagePath
                        });
                    }
                    else
                    {
                        break;
                    }

                    ctr++;
                }
            }

            return(shoppingCart);
        }
Exemple #4
0
        public static void AddItemToShoppingCart(Models.Inventory model, bool isBuy = false)
        {
            using (var ctx = new Data.AMEntDataContext())
            {
                var prod = ctx.Inventories.Where(x => x.ID == model.Id).SingleOrDefault();

                if (isBuy)
                {
                    Cart = null;
                    Cart = new List <Models.ShoppingCart>();
                }

                //var qty = new Random().Next(1, 5);
                int?qty      = model.Quantity;
                var lstPrice = prod.InventoryPrices != null?
                               prod.InventoryPrices.FirstOrDefault() != null?
                               prod.InventoryPrices.FirstOrDefault().InventoryListPrices != null && prod.InventoryPrices.FirstOrDefault().InventoryListPrices.Count() > 0 ?
                               prod.InventoryPrices.FirstOrDefault().InventoryListPrices.Max(a => a.ListPrice) : 0
                               : 0
                               : 0;

                var totalPrice = (qty ?? 0) * lstPrice;

                Cart.Add(new Models.ShoppingCart()
                {
                    CartId       = prod.ID,
                    ProductCode  = prod.ItemCode,
                    ProductName  = prod.Description,
                    Size         = Resource.StaticResource.Size[new Random().Next(0, 2)],
                    Color        = Resource.StaticResource.Color[new Random().Next(0, 4)],
                    Quantity     = qty ?? 0,
                    CurrencyName = "USD",
                    ListPrice    = lstPrice,
                    TotalPrice   = totalPrice,
                    ImagePath    = Resource.StaticResource.ImagePath
                });
            }
        }
        public static List <Models.Inventory> GetAllActiveInventories(string search, Models.Page.Pager pagedModel)
        {
            var result = new List <Models.Inventory>();

            using (var ctx = new Data.AMEntDataContext())
            {
                var data = ctx.Inventories
                           .Where(x => x.Status == 1 &&
                                  x.InventoryWarehouses.Sum(y => y.OnhandQty) > 0);

                _AllActiveInventoriesCount = data.Count();

                if (string.IsNullOrWhiteSpace(search))
                {
                    result = data
                             .Select(x => new Models.Inventory
                    {
                        Id          = x.ID,
                        ItemCode    = x.ItemCode,
                        Description = x.Description,
                        ListPrice   = x.InventoryPrices != null ?
                                      x.InventoryPrices.FirstOrDefault() != null ?
                                      x.InventoryPrices.FirstOrDefault().InventoryListPrices != null && x.InventoryPrices.FirstOrDefault().InventoryListPrices.Count() > 0 ?
                                      x.InventoryPrices.FirstOrDefault().InventoryListPrices.Max(a => a.ListPrice) : 0
                                    : 0
                                : 0,
                        ImagePath = Resource.StaticResource.ImagePath
                    })
                             .Skip(pagedModel.Start)
                             .Take(pagedModel.ItemsPerPage)
                             .ToList();
                }
                else
                {
                    var newData = data
                                  .Where(x => x.ItemCode.ToLower().Contains(search.ToLower()));

                    _AllActiveInventoriesCount = newData.Count();

                    result = newData
                             .Select(x => new Models.Inventory
                    {
                        Id          = x.ID,
                        ItemCode    = x.ItemCode,
                        Description = x.Description,
                        ListPrice   = x.InventoryPrices != null ?
                                      x.InventoryPrices.FirstOrDefault() != null ?
                                      x.InventoryPrices.FirstOrDefault().InventoryListPrices != null && x.InventoryPrices.FirstOrDefault().InventoryListPrices.Count() > 0 ?
                                      x.InventoryPrices.FirstOrDefault().InventoryListPrices.Max(a => a.ListPrice) : 0
                                    : 0
                                : 0,
                        ImagePath = Resource.StaticResource.ImagePath
                    })
                             .Skip(pagedModel.Start)
                             .Take(pagedModel.ItemsPerPage)
                             .ToList();
                }
            }

            return(result);
        }