Beispiel #1
0
        public ProductsModel GetAll()
        {
            var           productsList = new List <tblProduct>();
            ProductsModel model        = new ProductsModel();

            using (var db = new chemicalsEntities())
            {
                var products = db.tblProducts;
                model.productsList = products;
            }
            return(model);
        }
Beispiel #2
0
 public ActionResult Index(int startIndex, int pageSize)
 {
     try
     {
         using (var db = new chemicalsEntities())
         {
             var products = db.tblProducts.OrderBy(p => p.Id).Skip(startIndex).Take(pageSize).ToList();
             return(View(products));
         }
     }
     catch (Exception ex)
     {
         ViewBag.FileStatus = "Exception happened server could not be contacted !! Very Sorry";
         return(View());
     }
 }
Beispiel #3
0
 public ActionResult Open(int Id)
 {
     try
     {
         using (var db = new chemicalsEntities())
         {
             tblProduct record = db.tblProducts.ToList().FirstOrDefault(p => p.Id == Id);
             if (record.FileContent != null)
             {
                 return(File(record.FileContent, "application/pdf", record.FilePath));
             }
             else
             {
                 ViewBag.FileStatus = "File Not Found";
                 return(View());
             }
         }
     }
     catch (Exception ex)
     {
         ViewBag.FileStatus = "Exception happened server could not be contacted !! Very Sorry";
         return(View());
     }
 }
Beispiel #4
0
        public async Task <ActionResult> Browse(int Id, string productName, string productUrl)
        {
            try
            {
                ViewBag.Message  = productName;
                ViewBag.Message2 = productUrl;
                var fileName = productName;
                //var path = String.Format(@"{0}DataSheets\", AppDomain.CurrentDomain.BaseDirectory);
                var path = @"~\DataSheets\";

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                HttpClient client = new HttpClient();

                Uri _uri = new Uri(productUrl);

                client.BaseAddress = _uri;
                await client.GetAsync(_uri.LocalPath);

                client.DefaultRequestHeaders.Clear();
                var responce = client.GetAsync(_uri.LocalPath);
                responce.Wait();
                byte[] result = await responce.Result.Content.ReadAsByteArrayAsync();

                string totPath = fileName;
                if (!string.IsNullOrEmpty(path))
                {
                    string Folder = Server.MapPath(path);
                    totPath = Path.Combine(Folder, fileName);
                }
                bool isPdfFile = false;
                if (responce.Result.StatusCode == HttpStatusCode.OK)
                {
                    string contentType = "";
                    if (responce.Result.Content.Headers.ContentType.MediaType.ToString() == "application/pdf")
                    {
                        contentType = "application/pdf";
                        fileName    = fileName + ".pdf";
                        isPdfFile   = true;
                    }
                    else if (responce.Result.Content.Headers.ContentType.MediaType.ToString() == "text/html")
                    {
                        contentType = "text/html";
                        fileName    = fileName + ".text";
                        isPdfFile   = false;
                    }
                    using (var db = new chemicalsEntities())
                    {
                        tblProduct record = db.tblProducts.ToList().FirstOrDefault(p => p.Id == Id);
                        record.FilePath        = fileName;
                        record.IsAvailable     = isPdfFile;
                        record.FileContent     = result;
                        db.Entry(record).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    FileContentResult fileContentResult = File(result, contentType, fileName);
                    ViewBag.FileStatus = "File Saved Success :)";
                    //return View();
                    return(fileContentResult);
                }
                else
                {
                    using (var db = new chemicalsEntities())
                    {
                        tblProduct record = db.tblProducts.ToList().FirstOrDefault(p => p.Id == Id);
                        record.FilePath        = fileName;
                        record.IsAvailable     = false;
                        db.Entry(record).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    ViewBag.FileStatus = "File Not Found !! Very Sorry";
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ViewBag.FileStatus = "Exception happened server could not be contacted !! Very Sorry";
                return(View());
            }
        }