Esempio n. 1
0
        public ActionResult UploadFiles(FaultDTO model, HttpPostedFileBase postedfile)
        {
            ViewBag.Priorities    = FaultPrioritiesRepository.GetActivePriorities();
            ViewBag.Complexities  = FaultComplexityRepository.GetActiveComplexities();
            ViewBag.Companies     = CompanyRepository.GetAllActive();
            ViewBag.Enigineers    = UsersinfoRepository.GetAllActiveEngineers();
            ViewBag.UploadedFiles = FaultRepository.GetFilesByFaultId(model.Id);

            try
            {
                var imageLibrary = new FaultLibrary();
                if (postedfile != null)
                {
                    var filePath = SaveImage(postedfile);
                    imageLibrary.FileName     = postedfile.FileName;
                    imageLibrary.Url          = filePath;
                    imageLibrary.FaultId      = model.Id;
                    imageLibrary.ModifiedBy   = this.CurrentSession.LoggedUser.Id;
                    imageLibrary.ModifiedDate = DateTime.Now;
                    imageLibrary.CreatedDate  = DateTime.Now;
                    imageLibrary.CreatedBy    = this.CurrentSession.LoggedUser.Id;
                }

                FaultRepository.SaveFile(imageLibrary);
                TempData["Message"] = "Files uploaded successfully !!!";
                TempData["IsError"] = false;
                return(RedirectToAction("Edit", new { id = model.Id }));
            }
            catch (Exception ex)
            {
                TempData["Message"] = "Files uploaded successfully !!!";
                TempData["IsError"] = false;
            }
            return(RedirectToAction("Edit", new { id = model.Id }));
        }
Esempio n. 2
0
 private void btnUpload_Click(object sender, EventArgs e)
 {
     try
     {
         foreach (var file in uploadedFiles)
         {
             var imageLibrary = new FaultLibrary();
             imageLibrary.FileName     = file.Split('@')[0];
             imageLibrary.Url          = file.Split('@')[1];
             imageLibrary.FaultId      = _customFault.Id;
             imageLibrary.ModifiedBy   = AuthenticatedDetails.LoggedUser.Id;
             imageLibrary.ModifiedDate = DateTime.Now;
             imageLibrary.CreatedDate  = DateTime.Now;
             imageLibrary.CreatedBy    = AuthenticatedDetails.LoggedUser.Id;
             FaultRepository.SaveFile(imageLibrary);
             UploadedFiles = FaultRepository.GetFilesByFaultId(_customFault.Id).ToList();
             dataGridView1.AutoGenerateColumns = false;
             dataGridView1.DataSource          = UploadedFiles;
         }
         MessageBox.Show("Files Added Successfully !!!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to load form", "Error !!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }