예제 #1
0
		private void attach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.Category = this;
		}
예제 #2
0
		private void detach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.Category = null;
		}
예제 #3
0
 partial void UpdateProduct(Product instance);
예제 #4
0
 partial void DeleteProduct(Product instance);
예제 #5
0
 partial void InsertProduct(Product instance);
예제 #6
0
 public void Save(Product model)
 {
     throw new NotImplementedException("ProductDataContext is removed, use EF!");
     //_dataContext.Products.InsertOnSubmit(model);
     //_dataContext.SubmitChanges();
 }
예제 #7
0
 public void Update(Product model)
 {
     var p = Items.SingleOrDefault(x => x.Id == model.Id);
     p.Name = model.Name;
     _dataContext.SubmitChanges();
 }
예제 #8
0
        private ProductsByCategoryViewModel GetProductsByCategories(int posId)
        {
            var con = new System.Data.SqlClient.SqlConnection(MySettings.ConnectionStringDefault);
            con.Open();
            var cmd = new System.Data.SqlClient.SqlCommand(
            @"select
            --    top 1000
            p.id as id,             -- 0
            p.internal_code,
            p.uid,
            p.name,
            p.price,
            c.id as category_id,    -- 5
            c.name as category_name,
            isnull(pd.parameter_value, '') as size_name,
            isnull(pd.price_minor, 0) as price_minor,
            isnull(pd.price_release_minor, 0) as price_release_minor,
            isnull(pd.quantity, 0),             -- 10
            isnull(pd.id, 0) as price_id,
            isnull(pd.data_json, '') as data_json
            from product p
            join category c on p.category_id = c.id
            left join product_detail pd on p.id = pd.product_id
            where p.pos_id = " + posId + @"
            order by p.id", con);

            ProductsByCategoryViewModel productsByCategories = new ProductsByCategoryViewModel();
            var products = new List<OnBalance.Domain.Entities.Product>();
            decimal priceMinor, priceReleaseMinor;
            int priceId;
            string dataJson;
            Dictionary<int, string> categoryNames = new Dictionary<int, string>();

            var r = cmd.ExecuteReader();
            while (r.Read())
            {
                var p = new Product();
                p.Id = r.GetInt32(0);
                p.InternalCode = r.GetString(1);
                p.Uid = r.GetString(2);
                p.Name = r.GetString(3);
                //p.Price = r.GetDecimal(4);
                p.CategoryId = r.GetInt32(5);
                p.Price = r.GetDecimal(9);
                priceMinor = r.GetDecimal(8);
                priceReleaseMinor = r.GetDecimal(9);
                var psq = new ProductSizeQuantity();
                psq.SizeName = r.GetString(7);
                psq.Quantity = r.GetInt32(10);
                priceId = r.GetInt32(11);
                dataJson = r.GetString(12);

                // Store category name
                categoryNames[p.CategoryId] = r.GetString(6);

                var existing = products.FirstOrDefault(x => x.Id == p.Id);
                if (existing == null)
                {
                    var newP = new Domain.Entities.Product
                    {
                        Id = p.Id,
                        InternalCode = p.InternalCode,
                        Uid = p.Uid,
                        Name = p.Name,
                        CategoryId = p.CategoryId

                    };
                    newP.ProductDetails.Add(new Domain.Entities.ProductDetail
                    {
                        Id = priceId,
                        ParameterValue = psq.SizeName,
                        Quantity = psq.Quantity,
                        PriceMinor = priceMinor,
                        PriceReleaseMinor = priceReleaseMinor,
                        DataJson = dataJson,
                    });
                    products.Add(newP);
                }
                else
                {
                    existing.ProductDetails.Add(new Domain.Entities.ProductDetail {
                        Id = priceId,
                        ParameterValue = psq.SizeName,
                        Quantity = psq.Quantity,
                        PriceMinor = priceMinor,
                        PriceReleaseMinor = priceReleaseMinor,
                        DataJson = dataJson
                    });
                }
            }

            productsByCategories = new ProductsByCategoryViewModel(products);

            // Fill category names
            foreach (var c in productsByCategories.ProductsByCategories)
            {
                var firstProduct = c.Products.FirstOrDefault();
                if (firstProduct != null)
                {
                    c.CategoryName = categoryNames.Keys.Contains(firstProduct.CategoryId) ? categoryNames[firstProduct.CategoryId] : "";
                }
            }
            return productsByCategories;
        }
예제 #9
0
        public ActionResult DoNewProduct(ProductNew model)
        {
            try
            {
                decimal d;
                var productPdo = new Domain.Entities.Product();
                productPdo.PosId = model.PosId;
                productPdo.CategoryId = model.CategoryId;
                productPdo.Name = HttpUtility.HtmlEncode(model.ProductName);
                productPdo.CreatedAt = DateTime.UtcNow;
                productPdo.UserId = "gj";
                productPdo.StatusId = (byte)Status.Pending;
                productPdo.InternalCode = model.InternalCode.StartsWith(productPdo.UserId, StringComparison.InvariantCultureIgnoreCase) ? model.InternalCode : String.Concat(productPdo.UserId.ToUpper(), "_ES_", model.InternalCode);
                productPdo.Uid = string.Concat("GJ_ES_", model.InternalCode);
                if (decimal.TryParse(model.PriceStr, out d))
                {
                    productPdo.Price = d;
                }

                _productRepository.Save(productPdo);
                _productRepository.SubmitChanges();

                var product = new Product(productPdo);

                ViewBag.TotalSizes = model.TotalSizes;
                return PartialView(product);
            }
            catch (Exception ex)
            {

                throw;
            }
        }