public Task <int> Add() { var addFile = new tblFile { MainId = DMainId, Marlik = DMarlik, FileType_Id = DFileTypeId, Violation_Id = DViolationId, FileNum = DFileNum, FileYear = DFileYear, PermitNum = DPermitNum, PermitYear = DPermitYear, Mantaghe = DMantaghe, Nahie = DNahie, Mahaleh = DMahaleh, Block = DBlock, Melk = DMelk, Radif = DRadif, Address = DAddress, PostalCode = DPostalCode, VoteNum = DVoteNum, InArchives = DInArchives, Separation = DSeparation, Aggregation = DAggregation, DateInsert = DDateInsert, Description = DDescription }; _dbMunicipalArchiveEntities.tblFile.Add(addFile); _dbMunicipalArchiveEntities.SaveChanges(); return(Task.Run(() => addFile.Id)); }
public HttpResponseMessage SaveFile() { //Create HTTP Response. HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); //Check if Request contains File. if (HttpContext.Current.Request.Files.Count == 0) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } //Read the File data from Request.Form collection. HttpPostedFile postedFile = HttpContext.Current.Request.Files[0]; //Convert the File data to Byte Array. byte[] bytes; using (BinaryReader br = new BinaryReader(postedFile.InputStream)) { bytes = br.ReadBytes(postedFile.ContentLength); } //Insert the File to Database Table. FilesEntities entities = new FilesEntities(); tblFile file = new tblFile { Name = Path.GetFileName(postedFile.FileName), ContentType = postedFile.ContentType, Data = bytes }; entities.tblFiles.Add(file); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, new { id = file.id, Name = file.Name })); }
internal static async Task <int> InsertCandidateFiles(tblCandidate can, tblFile file, long fileTypeid, DateTime?exdate = null) { try { using (db = new eMSPEntities()) { var scandidate = db.tblCandidateFiles.Add(new tblCandidateFile { FileID = file.ID, FileTypeID = fileTypeid, CandidateID = can.ID, IsActive = true, IsDeleted = false, ExpiryDate = exdate, CreatedTimestamp = can.CreatedTimestamp, CreatedUserID = can.CreatedUserID, UpdatedTimestamp = can.UpdatedTimestamp, UpdatedUserID = can.UpdatedUserID }); return(await Task.Run(() => db.SaveChangesAsync())); } } catch (Exception ex) { throw; } }
public FileResult DownloadFile(int?fileId) { ApplicationDbContext entities = new ApplicationDbContext(); tblFile file = entities.tblFiles.ToList().Find(p => p.id == fileId.Value); return(File(file.Data, file.ContentType, file.Name)); }
internal static async Task <CandidateCreateModel> Update(CandidateCreateModel model) { try { tblFile file = null; await UpdateCandidate(model.Candidate.ConvertTotblCandidate()); await UpdateContacts(model.CandidateContact, model.Candidate.ConvertTotblCandidate()); await UpdateCandidateFiles(model.CandidateFile, model.Candidate.ConvertTotblCandidate()); await UpdateCandidateIndustries(model.CandidateIndustries.Select(a => Convert.ToInt32(a)).ToList(), model.Candidate.ConvertTotblCandidate()); await UpdateCandidateSkills(model.CandidateSkills.Select(a => Convert.ToInt32(a)).ToList(), model.Candidate.ConvertTotblCandidate()); tblCandidate t = await Task.Run(() => Get(Convert.ToInt64(model.Candidate.id))); return(t.ConvertToCandidateCreateModel()); } catch (Exception) { throw; } }
internal static async Task UpdateCandidateFiles(List <FileModel> model, tblCandidate Candidate) { try { int x = 0; tblFile fi = null; using (db = new eMSPEntities()) { await db.tblCandidateFiles.Where(a => a.CandidateID == Candidate.ID).ForEachAsync(a => { a.IsActive = false; a.IsDeleted = true; }); await Task.Run(() => db.SaveChangesAsync()); foreach (FileModel a in model) { fi = await Task.Run(() => InsertFiles(a.ConvertTotblFile())); x = await Task.Run(() => InsertCandidateFiles(Candidate, fi, Convert.ToInt64(a.FileTypeId))); } //return model; } } catch (Exception) { throw; } }
private static void InsertLinesFields(DataTable dt, tblFile fl) { try { //clsDAL.ExecuteSQL("truncate table tblFileDetailField", "BPS"); string sqlConnectionString = ""; sqlConnectionString = clsDAL.GetCon("ECR"); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "tblFileDetailField"; bulkCopy.BulkCopyTimeout = 180; foreach (DataColumn dc in dt.Columns) { bulkCopy.ColumnMappings.Add(new SqlBulkCopyColumnMapping(dc.ColumnName, dc.ColumnName)); } bulkCopy.WriteToServer(dt); } } catch (Exception ex) { //LogProgress(q, ex.ToString()); } }
public ActionResult Action(tblFile objSubmit) { if (System.IO.File.Exists(Server.MapPath(ConfigWeb.TempPath + objSubmit.FileName))) { objSubmit.Size = new System.IO.FileInfo(Server.MapPath(ConfigWeb.TempPath + objSubmit.FileName)).Length; FileUtility.MoveFile(StaticEnum.FileType.File, objSubmit.FileName); } if (objSubmit.ID == 0) { objSubmit.DateCreated = DateTime.Now; objSubmit.DateUpdated = DateTime.Now; objSubmit.IsDeleted = false; objSubmit.IsShow = true; fileRepository.Add(objSubmit); } else { var obj = fileRepository.GetById <tblFile>(objSubmit.ID); UpdateModel(obj); objSubmit.DateUpdated = DateTime.Now; fileRepository.Update(obj); } return(Json(new { Error = false }, JsonRequestBehavior.AllowGet)); }
public static void HandleZipAsync(string startPath, string zipPath, tblFile file) { //Task.Run(() => ZipFile.CreateFromDirectory(startPath, zipPath)); ZipFile.CreateFromDirectory(startPath, zipPath); var dbCtx = new CUATRGEntities4(); file.EndStamp = DateTime.Now; dbCtx.SaveChanges(); }
private void InsertFile(int productId, byte[] onlineFile) { tblFile file = new tblFile(); file.Id = productId; file.File = onlineFile; _unitOfWork.Files.Insert(file); }
internal static async Task <CandidateCreateModel> Insert(CandidateCreateModel model) { try { int x = 0; tblContact contact = null; tblFile file = null; tblCandidate candidate = await Task.Run(() => InsertCandidate(model.Candidate.ConvertTotblCandidate())); x = await Task.Run(() => InsertSupplierCandidate(candidate, model.SupplierId)); if (model.CandidateContact.Count > 0) { foreach (CandidateContactModel a in model.CandidateContact) { contact = await Task.Run(() => InsertContacts(a.ConvertTotblContact())); x = await Task.Run(() => InsertCandidateContacts(candidate, contact, a.IsPrimary)); } } if (model.CandidateFile.Count > 0) { foreach (FileModel a in model.CandidateFile) { file = await Task.Run(() => InsertFiles(a.ConvertTotblFile())); x = await Task.Run(() => InsertCandidateFiles(candidate, file, Convert.ToInt64(a.FileTypeId), a.ExpiryDate)); } } if (model.CandidateIndustries != null) { x = await Task.Run(() => InsertCandidateIndustries(model.CandidateIndustries.Select(a => Convert.ToInt32(a)).ToList(), candidate)); } if (model.CandidateSkills != null) { x = await Task.Run(() => InsertCandidateSkills(model.CandidateSkills.Select(a => Convert.ToInt32(a)).ToList(), candidate)); } candidate = await Task.Run(() => Get(candidate.ID)); return(candidate.ConvertToCandidateCreateModel()); } catch (Exception) { throw; } }
public void AddFile(FileItem item) { var tblFile = new tblFile { Description = item.Description, Path = item.Path, ProductId = item.ProductId, SupplierInvoiceId = item.SupplierInvoiceId, Position = item.Position }; Db.Set<tblFile>().Add(tblFile); Db.SaveChanges(); item.Id = tblFile.Id; }
public void AddFile(FileItem item) { var tblFile = new tblFile { Description = item.Description, Path = item.Path, ProductId = item.ProductId, SupplierInvoiceId = item.SupplierInvoiceId, Position = item.Position }; Db.Set <tblFile>().Add(tblFile); Db.SaveChanges(); item.Id = tblFile.Id; }
public static FileModel ConvertToCandidateFileModel(this tblFile data, int fileTypeId = 0) { return(new FileModel() { ID = Convert.ToInt32(data.ID), FileName = data.FileName, FilePath = data.FilePath, FileVersionNumber = data.FileVersionNumber, isActive = data.IsActive, isDeleted = data.IsDeleted, createdUserID = data.CreatedUserID, updatedUserID = data.UpdatedUserID, createdTimestamp = data.CreatedTimestamp, updatedTimestamp = data.UpdatedTimestamp, FileTypeId = fileTypeId }); }
internal static async Task <tblFile> InsertFiles(tblFile model) { try { using (db = new eMSPEntities()) { var file = db.tblFiles.Add(model); int x = await Task.Run(() => db.SaveChangesAsync()); return(file); } } catch (Exception) { throw; } }
public FileContentResult OpenFile(int id) { tblFile file = unitOfWork.Files.GetByID(id); if (file == null) { return(null); } try { return(File(file.File, "application/pdf")); } catch { return(null); } }
internal static async Task UpdateFiles(tblFile model) { try { using (db = new eMSPEntities()) { db.Entry(model).State = EntityState.Modified; int x = await Task.Run(() => db.SaveChangesAsync()); //return model; } } catch (Exception) { throw; } }
public JsonResult UploadDocument(AdminDocument docs) { var file = docs.Document; int mystudntid = Convert.ToInt32(Session["StudentID"]); var grpid = db.Student_Group.Where(p => p.Student_1_ID == mystudntid || p.Student_2_ID == mystudntid).FirstOrDefault(); if (file != null) { UploadstdntDeliverables(docs); } tblFile docsbystdnt = new tblFile(); docsbystdnt.Document_Name = docs.Document_Name; docsbystdnt.Document_Path = docs.DocumentPath; docsbystdnt.Is_Active = true; docsbystdnt.Date_Created = DateTime.Now; docsbystdnt.Group_ID = grpid.Group_Id; db.tblFiles.Add(docsbystdnt); db.SaveChanges(); return(Json(new { success = true, msg = "Saved" }, JsonRequestBehavior.AllowGet)); }
public HttpResponseMessage GetFile(int fileId) { //Create HTTP Response. HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); //Fetch the File data from Database. FilesEntities entities = new FilesEntities(); tblFile file = entities.tblFiles.ToList().Find(p => p.id == fileId); //Set the Response Content. response.Content = new ByteArrayContent(file.Data); //Set the Response Content Length. response.Content.Headers.ContentLength = file.Data.LongLength; //Set the Content Disposition Header Value and FileName. response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentDisposition.FileName = file.Name; //Set the File Content Type. response.Content.Headers.ContentType = new MediaTypeHeaderValue(file.ContentType); return(response); }
private void UpdateFile(tblFile file) { _unitOfWork.Files.Update(file); }
public FileResult DownloadFile(int?fileId) { tblFile file = db.tblFiles.ToList().Find(p => p.ID == fileId.Value); return(File(file.Data, file.ContentType, file.Name)); }
public static int ReadXLAndSplit(string strPath) { try { ECREntities db = clsStart.efdbECR(); tblFile fl = new tblFile(); fl.FL_Desc = strPath; fl.FL_DateCreated = DateTime.Now; fl.FL_Date = DateTime.Now; fl.FTID = 0; db.tblFile.Add(fl); db.SaveChanges(); if (fl.FLID > 0) { DataTable dt = new DataTable(); string strField = ""; dt.Columns.Add("FLID"); Int32 i = 0; for (i = 1; i <= 113; i++) { strField = "F" + i.ToString(); dt.Columns.Add(strField); } Int32 intRow = 0; try { var excelFile = new ExcelQueryFactory(strPath); var worksheetNames = excelFile.GetWorksheetNames(); string strSheet = worksheetNames.First(); var qry = from a in excelFile.Worksheet(strSheet) select a; foreach (var row in qry) { dt.Rows.Add(fl.FLID); i = 1; foreach (string cell in row) { strField = "F" + i.ToString(); string strVal = cell.ToString(); if (i < 114) { if (strVal.Length > 48) { strVal = strVal.Substring(0, 48); } try { dt.Rows[intRow][strField] = strVal; } catch (Exception ex) { Debug.WriteLine(ex.Message); } } i = i + 1; } intRow = intRow + 1; } InsertLinesFields(dt, fl); return(fl.FLID); } catch (Exception ex) { return(0); //LogProgress(q, ex.ToString()); } } else { return(0); } } catch (Exception ex) { return(0); //LogProgress( //LogProgress(q, ex.ToString()); //return false; } return(0); //return true; }