Example #1
0
        protected void btnNewProduct_Click(object sender, EventArgs e)
        {
            //public Product(double price,string type, int supplierID)
            Product prod = new StandardProduct(Convert.ToInt32(txtPrice.Text), txtType.Text, Convert.ToInt32(txtSupplier.Text));

            Response.Write(prod.addProduct());
        }
Example #2
0
        public async Task CreateStandardProduct(StandardProduct productEntity, StandardProductCreateDto product)
        {
            if (product.ImageFile != null)
            {
                var blobName = _blobStorageService.GenerateFileName(product.ImageName);
                var filePath = await _blobStorageService.UploadFileBlobAsync(product.ImageFile, blobName, "standardproducts");

                productEntity.ImageName = product.ImageName;
                productEntity.ImagePath = filePath;
                productEntity.BlobName  = blobName;
            }


            productEntity.Status = StandardProductStatus.Produced;

            _repository.StandardProduct.CreateProduct(productEntity);
            await _repository.SaveAsync();

            var productWarehouseItem = new ProductWarehouseItem()
            {
                StandardProductId = productEntity.StandardProductId,
                Quantity          = 0
            };

            _repository.ProductWarehouseItem.CreateItem(productWarehouseItem);
            await _repository.SaveAsync();
        }
Example #3
0
        public static Product SelectProduct(int pid)
        {
            Product       retProduct = null;
            SqlConnection con        = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\werl\Documents\Visual Studio 2013\Projects\SystemsAnalysis\WebApplication2\WebApplication2\App_Data\Database.mdf;Integrated Security=True");
            SqlDataReader reader;
            SqlCommand    cmd = new SqlCommand("SELECT * FROM [Products] WHERE ProductID = " + pid, con);

            try
            {
                con.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    retProduct = new StandardProduct(Convert.ToInt32(reader["ProductID"]), (reader["Type"]).ToString(),
                                                     Convert.ToInt32(reader["SupplierID"]));
                }
                reader.Close();
                con.Close();
                return(retProduct);
            }
            catch (SqlException sqlEx)
            {
                Console.Write(sqlEx.Message);
                return(null);
            }
        }
        public IHttpActionResult GetStandardProduct(int id)
        {
            StandardProduct standardProduct = db.StandardProducts.Find(id);

            if (standardProduct == null)
            {
                return(NotFound());
            }

            return(Ok(standardProduct));
        }
        public IHttpActionResult PostStandardProduct(StandardProduct standardProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.StandardProducts.Add(standardProduct);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = standardProduct.Id }, standardProduct));
        }
Example #6
0
        public static Boolean checkWithAccessory(Cart cart, int custID)
        {
            List <int>    pIDs = new List <int>();
            Boolean       hasPhone = false, hasAccessory = false, hasBoth = false;
            string        connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            SqlConnection connection       = new SqlConnection(connectionString);
            String        sql = "SELECT ProductID FROM [ShoppingCart] WHERE CustomerID = @CustomerID";

            SqlCommand    command = new SqlCommand(sql, connection);
            SqlDataReader reader;


            connection.Open();

            command.Parameters.Add("@CustomerID", SqlDbType.Int);
            command.Parameters["@CustomerID"].Value = custID;

            reader = command.ExecuteReader();
            while (reader.HasRows)
            {
                while (reader.Read())
                {
                    pIDs.Add(reader.GetInt32(0));
                }
                reader.NextResult();
            }


            connection.Close();


            for (int i = 0; i < pIDs.Count; i++)
            {
                if (StandardProduct.getProductType(pIDs[i]).Contains("Phone"))
                {
                    hasPhone = true;
                }
                else if (StandardProduct.getProductType(pIDs[i]).Contains("Accessory"))
                {
                    hasAccessory = true;
                }
            }

            if (hasPhone && hasAccessory)
            {
                hasBoth = true;
            }

            return(hasBoth);
        }
Example #7
0
        public async Task UpdateStandardProduct(StandardProduct productEntity, StandardProductUpdateDto product)
        {
            if (product.ImageFile != null)
            {
                var blobName = _blobStorageService.GenerateFileName(productEntity.ImageName);
                var filePath = await _blobStorageService.UploadFileBlobAsync(product.ImageFile, blobName, "standardproducts");

                productEntity.ImagePath = filePath;
                productEntity.BlobName  = blobName;
            }
            productEntity.StandardProductCategoryId = product.StandardProductCategoryId;

            var category = await _repository.StandardProductCategory.GetCategoryByIdAsync(productEntity.StandardProductCategoryId);

            productEntity.StandardProductCategory = category;

            _repository.StandardProduct.UpdateProduct(productEntity);
            await _repository.SaveAsync();
        }
Example #8
0
        public static double getTotal(int custID)
        {
            double total = 0.0;

            List <int> pIDs       = new List <int>();
            List <int> quantities = new List <int>();

            string        connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            SqlConnection connection       = new SqlConnection(connectionString);
            String        sql = "SELECT ProductID, Quantity FROM [ShoppingCart] WHERE CustomerID = @CustomerID";

            SqlCommand    command = new SqlCommand(sql, connection);
            SqlDataReader reader;


            connection.Open();

            command.Parameters.Add("@CustomerID", SqlDbType.Int);
            command.Parameters["@CustomerID"].Value = custID;

            reader = command.ExecuteReader();
            while (reader.HasRows)
            {
                while (reader.Read())
                {
                    pIDs.Add(reader.GetInt32(0));
                    quantities.Add(reader.GetInt32(1));
                }
                reader.NextResult();
            }


            connection.Close();


            for (int i = 0; i < pIDs.Count; i++)
            {
                total += StandardProduct.getProductPrice(pIDs[i]) * quantities[i];
            }

            return(total);
        }
 public void Update(StandardProduct standard)
 {
     throw new NotImplementedException();
 }
 public void Insert(StandardProduct standard)
 {
     throw new NotImplementedException();
 }
 protected void btnNewProduct_Click(object sender, EventArgs e)
 {
     //public Product(double price,string type, int supplierID)
     Product prod = new StandardProduct(Convert.ToInt32(txtPrice.Text), txtType.Text, Convert.ToInt32(txtSupplier.Text));
     Response.Write(prod.addProduct());
 }
 protected void btnEditProduct_Click(object sender, EventArgs e)
 {
     Product prod = new StandardProduct(Convert.ToInt32(lstProducts.SelectedItem.Value), Convert.ToInt32(txtPrice.Text), txtPrice.Text, Convert.ToInt32(txtSupplier.Text));
     Response.Write(prod.editProduct(Convert.ToInt32(txtPrice.Text), txtType.Text, Convert.ToInt32(txtSupplier.Text)));
 }
 public void Update(StandardProduct Product)
 {
     db.Entry(Product).State = System.Data.Entity.EntityState.Modified;
 }
 public void Insert(StandardProduct Product)
 {
     db.StandardProducts.Add(Product);
 }
 public void Delete(StandardProduct Product)
 {
     db.StandardProducts.Remove(Product);
 }
 public static Product SelectProduct(int pid)
 {
     Product retProduct = null;
     SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\werl\Documents\Visual Studio 2013\Projects\SystemsAnalysis\WebApplication2\WebApplication2\App_Data\Database.mdf;Integrated Security=True");
     SqlDataReader reader;
     SqlCommand cmd = new SqlCommand("SELECT * FROM [Products] WHERE ProductID = " + pid, con);
     try
     {
         con.Open();
         reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             retProduct = new StandardProduct(Convert.ToInt32(reader["ProductID"]), (reader["Type"]).ToString(),
                 Convert.ToInt32(reader["SupplierID"]));
         }
         reader.Close();
         con.Close();
         return retProduct;
     }
     catch (SqlException sqlEx)
     {
         Console.Write(sqlEx.Message);
         return null;
     }
 }
Example #17
0
        protected void btnDeleteProduct_Click(object sender, EventArgs e)
        {
            Product prod = new StandardProduct(Convert.ToInt32(lstProducts.SelectedItem.Value), Convert.ToInt32(txtPrice.Text), txtPrice.Text, Convert.ToInt32(txtSupplier.Text));

            Response.Write(prod.DeleteProduct());
        }