public void CreateJob(UploadJob job) { try { transaction = CurrentSession.BeginTransaction(); CurrentSession.Save(job); // Remove job from cache CurrentSession.Flush(); CurrentSession.Refresh(job); transaction.Commit(); } catch (Exception exception) { HandleException(exception); } }
// Helper to save files and create job in database public bool SaveFile(HttpPostedFileBase indicatorDataFile, UploadJobType jobType) { bool response; if (Request.Files == null) { return false; } var guid = Guid.NewGuid(); var file = Request.Files[0]; var actualFileName = file.FileName; var fileName = guid + Path.GetExtension(file.FileName); try { if (!Directory.Exists(AppConfig.UploadFolder)) { Directory.CreateDirectory(AppConfig.UploadFolder); } file.SaveAs(Path.Combine(AppConfig.UploadFolder, fileName)); var uploadJob = new UploadJob { DateCreated = DateTime.Now, Guid = guid, Filename = actualFileName, JobType = jobType, Status = UploadJobStatus.NotStart, UserId = UserDetails.CurrentUser().Id }; _fpmUploadRepository.CreateJob(uploadJob); response = true; } catch (Exception ex) { response = false; } return response; }
public bool UpdateJob(UploadJob job) { var isOk = false; try { transaction = CurrentSession.BeginTransaction(); CurrentSession.Update(job); CurrentSession.Flush(); // Remove object from cache CurrentSession.Flush(); CurrentSession.Refresh(job); transaction.Commit(); isOk = true; } catch (Exception exception) { HandleException(exception); } return isOk; }