Example #1
0
        public static List<Price> GetPriceHistory(string productNumber)
        {
            List<Price> priceHistory = new List<Price>();

            try
            {
                using (var ctx = new tIMSdbEntities())
                {
                    var query = from p in ctx.Prices
                                where p.ProductNumber == productNumber
                                orderby p.Datetime descending
                                select new Price
                                {
                                    Datetime = p.Datetime,
                                    WholesalePrice = p.Wholesale ?? 0.0m,
                                    RetailPrice = p.Retail ?? 0.0m
                                };

                    priceHistory = query.ToList();
                }
            }
            catch (Exception ex)
            {

            }

            return priceHistory;
        }
Example #2
0
        public static List<Category> GetCategories()
        {
            List<Category> categories = new List<Category>();

            using (var ctx = new tIMSdbEntities())
            {
                // load all categories from the database
                cats =  from c in ctx.Categories
                        orderby c.ParentId, c.Name
                        select new Category {
                            Name = c.Name,
                            Id = c.Id,
                            ParentId = c.ParentId
                        };

                // query just the parent categories
                var parentCats = from p in cats
                              where p.ParentId == 0
                              select p;

                foreach (var cat in parentCats)
                {
                    BuildList(cat, categories);
                }
            }

            return categories;
        }
Example #3
0
        public static List<Quantity> GetQuantityHistory(string productNumber)
        {
            List<Quantity> history = new List<Quantity>();

            try
            {
                using (var ctx = new tIMSdbEntities())
                {
                    var query = from q in ctx.Quantities
                                where q.ProductNumber == productNumber
                                orderby q.Datetime descending
                                select new Quantity {
                                    Count = q.Count,
                                    Datetime = q.Datetime
                                };

                    history = query.ToList();
                }
            }
            catch (Exception ex)
            {

            }

            return history;
        }
Example #4
0
        public static void Update(Product item)
        {
            try
            {
                using (var ctx = new tIMSdbEntities())
                {
                    // update product
                    var product = ctx.Products.First(i => i.ProductNumber == item.ProductNumber);
                    product.Description = item.Description;
                    product.Active = item.Active;
                    product.Category = item.Category;

                    // insert new price
                    var price = new Prices
                    {
                        ProductNumber = item.ProductNumber,
                        Wholesale = item.WholesalePrice,
                        Retail = item.RetailPrice,
                        Datetime = DateTime.Now
                    };
                    ctx.AddToPrices(price);

                    // insert new quantity
                    var quantity = new Quantities
                    {
                        ProductNumber = item.ProductNumber,
                        Count = item.Quantity,
                        Datetime = DateTime.Now
                    };
                    ctx.Quantities.AddObject(quantity);

                    ctx.SaveChanges();
                }
            }
            catch(Exception ex)
            {

            }
        }