Exemple #1
0
        //Increase product quantity
        public static async Task IncreaseProductQuantity(Product product)
        {
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            try
            {
                List <Product> products = await GetProductsAsync();

                if (products.Where(x => x.Code == product.Code).Any())
                {
                    int quantity = products.Single <Product>(x => x.Code.Equals(product.Code)).Quantity + product.Quantity;
                    int Id       = products.Single <Product>(x => x.Code.Equals(product.Code)).Id;
                    sqlParameters.Add(new SqlParameter("Id", Id));
                    sqlParameters.Add(new SqlParameter("Quantity", quantity));
                    await DataAccessAsync.ExecSPAsync("IncreaseQuantityProduct", sqlParameters);
                }
                else
                {
                    throw new Exception("محصول به تعداد کافی موجود نیست");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(" مشکل در ثبت محصول " + "/n" + ex.Message);
            }
        }
Exemple #2
0
        //set product and check it's new
        public static async Task SetProduct(Product product)
        {
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter("Code", product.Code));
            sqlParameters.Add(new SqlParameter("Name", product.Name));
            sqlParameters.Add(new SqlParameter("Quantity", product.Quantity));
            try
            {
                List <Product> products = await GetProductsAsync();

                if (!products.Where(x => x.Code == product.Code).Any())
                {
                    await DataAccessAsync.ExecSPAsync("SetProduct", sqlParameters);
                }
                else
                {
                    throw new Exception("محصول با این کد موجود است");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("مشکل در ثبت محصول " + ex.Message);
            }
        }
Exemple #3
0
        // Get Sold product
        public static async Task <List <SoldProduct> > GetSoldProductsAsync()
        {
            List <SoldProduct> soldProducts = new List <SoldProduct>();
            DataTable          dtProduct    = await DataAccessAsync.ExecSPAsync("GetSoldProducts");

            //check info
            return(DataTableToList <SoldProduct>(dtProduct));
        }
Exemple #4
0
        //Delete product
        public static async Task DeleteProduct(Product product)
        {
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            sqlParameters.Add(new SqlParameter("Id", product.Id));

            try
            {
                List <Product> products = await GetProductsAsync();

                if (products.Where(x => x.Id == product.Id).Any())
                {
                    await DataAccessAsync.ExecSPAsync("DeleteProduct", sqlParameters);
                }
                else
                {
                    throw new Exception("محصول موجود نیست");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }