コード例 #1
0
        public ActionResult AddProduct(ProductCollectionModel collection)
        {
            try
            {
                // TODO: Add insert logic here
                if (Request.Form.Files.Count > 0)
                {
                    var    file   = Request.Form.Files[0];
                    byte[] buffer = new byte[file.Length];
                    file.OpenReadStream().Read(buffer, 0, (int)file.Length);
                    collection.FileName     = file.FileName;
                    collection.ProductImage = buffer;
                    azureBlobStorage.UploadToBlobAsync(collection);
                }
                else
                {
                    collection.FileName = "NoImage.png";
                }


                productoInventRepository.AddNewProduct(collection);
                sendEmailLogic.SendMail(collection);
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
コード例 #2
0
        public List <ProductCollectionModel> GetProductCollections()
        {
            SqlConnection sqlConnection = new SqlConnection(AdoSqlConnection.ConnectionString);

            sqlConnection.Open();
            var productCollections = new List <ProductCollectionModel>();

            using (var command = new SqlCommand("select top 50 ProductId,name,standardcost,ModifiedDate,productNumber from SalesLt.Product where discontinueddate is null order by 1 desc", sqlConnection))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ProductCollectionModel productCollection = new ProductCollectionModel();
                        productCollection.ProductId        = reader.GetInt32(0);
                        productCollection.ProductName      = reader.GetString(1);
                        productCollection.Price            = reader.GetDecimal(2);
                        productCollection.ModifiedDateTime = reader.GetDateTime(3);
                        productCollection.ProductNumber    = reader.GetString(4);
                        productCollections.Add(productCollection);
                    }
                }
            }
            sqlConnection.Close();
            return(productCollections);
        }
コード例 #3
0
        public ProductCollectionModel GetProductDetails(int productId)
        {
            SqlConnection sqlConnection = new SqlConnection(AdoSqlConnection.ConnectionString);

            sqlConnection.Open();
            var productCollection = new ProductCollectionModel();

            using (var command = new SqlCommand("select ProductId,name,standardcost,sellstartdate,ModifiedDate,productnumber from SalesLt.Product where discontinueddate is null and Productid=" + productId + "order by 1 desc", sqlConnection))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        productCollection.ProductId        = reader.GetInt32(0);
                        productCollection.ProductName      = reader.GetString(1);
                        productCollection.CreatedDateTime  = reader.GetDateTime(3);
                        productCollection.ProductNumber    = reader.GetString(5);
                        productCollection.Price            = reader.GetDecimal(2);
                        productCollection.ModifiedDateTime = reader.GetDateTime(4);
                    }
                }
            }
            sqlConnection.Close();
            return(productCollection);
        }
コード例 #4
0
 public ActionResult DeleteProduct(int id, ProductCollectionModel collection)
 {
     try
     {
         productoInventRepository.DeleteProduct(collection.ProductId);
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception ex)
     {
         return(View());
     }
 }
コード例 #5
0
        public ActionResult Edit(int id, ProductCollectionModel collection)
        {
            try
            {
                // TODO: Add update logic here

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
コード例 #6
0
 public ActionResult AddProduct(ProductCollectionModel collection)
 {
     try
     {
         // TODO: Add insert logic here
         productoInventRepository.AddNewProduct(collection);
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception ex)
     {
         return(View());
     }
 }
コード例 #7
0
        public async Task <int> UploadToBlobAsync(ProductCollectionModel productCollectionModel)
        {
            try
            {
                blob = _container.GetBlockBlobReference(blobPath + productCollectionModel.FileName);
                await blob.UploadFromByteArrayAsync(productCollectionModel.ProductImage, 0, productCollectionModel.ProductImage.Length);

                return(1);
            }
            catch (Exception)
            {
                return(0);
            }
        }
コード例 #8
0
        public int AddNewProduct(ProductCollectionModel productCollectionModel)
        {
            int           rowsAffected  = 0;
            SqlConnection sqlConnection = new SqlConnection(AdoSqlConnection.ConnectionString);

            sqlConnection.Open();
            using (var command = new SqlCommand("insert into salesLt.Product (Name,ProductNumber,standardcost,ListPrice,sellStartdate,ModifiedDate) values('" + productCollectionModel.ProductName + "','" + productCollectionModel.ProductNumber + "'," + productCollectionModel.Price + "," + productCollectionModel.Price + ",'" + productCollectionModel.CreatedDateTime.ToString("yyyy-MM-dd hh:mm") + "','" + DateTime.Now.ToString("yyyy-MM-dd hh: mm") + "')", sqlConnection))
            {
                rowsAffected = command.ExecuteNonQuery();
            }
            sqlConnection.Close();

            return(rowsAffected);
        }
コード例 #9
0
        public int EditProduct(ProductCollectionModel productCollectionModel)
        {
            int           rowsAffected  = 0;
            SqlConnection sqlConnection = new SqlConnection(AdoSqlConnection.ConnectionString);

            sqlConnection.Open();
            using (var command = new SqlCommand("update SalesLt.Product set Name = '" + productCollectionModel.ProductName
                                                + "', ProductNumber = '" + productCollectionModel.ProductNumber
                                                + "', standardCost =" + productCollectionModel.Price
                                                + ", sellStartdate = '" + productCollectionModel.CreatedDateTime
                                                + "', Thumbnailphotofilename = '" + productCollectionModel.FileName
                                                + "'where ProductId = " + productCollectionModel.ProductId, sqlConnection))
            {
                rowsAffected = command.ExecuteNonQuery();
            }
            sqlConnection.Close();

            return(rowsAffected);
        }
コード例 #10
0
 public ActionResult EditProduct(ProductCollectionModel collection)
 {
     try
     {
         if (Request.Form.Files.Count > 0)
         {
             var    file   = Request.Form.Files[0];
             byte[] buffer = new byte[file.Length];
             file.OpenReadStream().Read(buffer, 0, (int)file.Length);
             collection.FileName     = file.FileName;
             collection.ProductImage = buffer;
             azureBlobStorage.UploadToBlobAsync(collection);
         }
         productoInventRepository.EditProduct(collection);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
コード例 #11
0
        public async Task SendMail(ProductCollectionModel collection)
        {
            //var proxy = new WebProxy()
            //{
            //    Address = new Uri($"http://gbips-i-ss50.int.dir.willis.com:8080"),
            //    BypassProxyOnLocal = false,
            //    UseDefaultCredentials = true,
            //    Credentials = new NetworkCredential("BMSri", "June2018&", "INT")
            //};

            //var client = new SendGridClient(proxy, apiKey);
            var client = new SendGridClient(apiKey);
            var msg    = new SendGridMessage()
            {
                From             = new EmailAddress("*****@*****.**", "Products Admin Team"),
                Subject          = "Product Inventory - New Product",
                PlainTextContent = "Congratulations!!!!!!!!!!!" + "You have succesfully added" + " " + collection.ProductName + ":)"
            };

            msg.AddTo(new EmailAddress(collection.CustomerEmail, "Customer"));
            var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
        }
コード例 #12
0
        public List <ProductCollectionModel> GetProductCollectionsWithImage()
        {
            SqlConnection sqlConnection = new SqlConnection(AdoSqlConnection.ConnectionString);

            sqlConnection.Open();
            var productCollections = new List <ProductCollectionModel>();

            using (var command = new SqlCommand("select distinct ProductModelId,thumbnailphoto from salesLt.Product where ProductModelid in (5, 11, 12, 123)", sqlConnection))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ProductCollectionModel productCollection = new ProductCollectionModel();
                        productCollection.ProductImage = (byte[])reader[1];
                        productCollections.Add(productCollection);
                    }
                }
            }
            sqlConnection.Close();
            productCollections.ElementAt(0).ActiveClass = "active";
            return(productCollections);
        }
コード例 #13
0
        public List <ProductCollectionModel> GetProductCollectionsWithImage()
        {
            SqlConnection sqlConnection = new SqlConnection(AdoSqlConnection.ConnectionString);

            sqlConnection.Open();
            var productCollections = new List <ProductCollectionModel>();

            using (var command = new SqlCommand("select top 4 ProductId,thumbnailphotofileName from salesLt.Product Order by ProductId desc", sqlConnection))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ProductCollectionModel productCollection = new ProductCollectionModel();
                        productCollection.FileName = reader.GetString(1);
                        productCollections.Add(productCollection);
                    }
                }
            }
            sqlConnection.Close();
            productCollections.ElementAt(0).ActiveClass = "active";
            return(productCollections);
        }
コード例 #14
0
 public List <ProductCollectionModel> EditProduct(ProductCollectionModel productCollectionModel)
 {
     throw new NotImplementedException();
 }