public ProductValueObject GetProductById(int?rowId)
        {
            var data = _productDataAccessLayer.GetProductById(rowId);

            return((from DataRow row in data.Rows
                    select new ProductValueObject(int.Parse(row["id"].ToString()),
                                                  row["name"].ToString(), int.Parse(row["id_type"].ToString()),
                                                  uint.Parse(row["price"].ToString()), row["description"].ToString(), int.Parse(row["new"].ToString()), uint.Parse(row["unitInStock"].ToString()), uint.Parse(row["unitOnBill"].ToString()))).First());
        }
Example #2
0
        public bool UpdateProduct(int id)
        {
            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string  json       = new StreamReader(req).ReadToEnd();
            var     pro        = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            Product updProduct = productDAL.GetProductById(id);

            if (null == updProduct)
            {
                return(false);
            }
            if (pro.ContainsKey("Name"))
            {
                if ("" == pro["Name"])
                {
                    return(false);
                }
                else
                {
                    updProduct.Name = pro["Name"];
                }
            }
            if (pro.ContainsKey("Price"))
            {
                Decimal price = 0;
                try
                {
                    price = Convert.ToDecimal(pro["Price"]);
                }
                catch (Exception)
                {
                    return(false);
                }
                updProduct.Price = price;
            }
            return(productDAL.UpdateProduct(updProduct));
        }
Example #3
0
        private bool checkProduct(int?productId)
        {
            if (null == productId)
            {
                return(false);
            }
            int id = Convert.ToInt32(productId);
            ProductDataAccessLayer productDAL = new ProductDataAccessLayer();

            if (null == productDAL.GetProductById(id))
            {
                return(false);
            }
            return(true);
        }