public ActionResult ReportLogApprove(Guid id) { var model = _repository.Find<REPORTLOG>(id); REPORTLOG report=_repository.Fetch<REPORTLOG>().Where(p=>p.Id == id).First(); string fileLocation = HttpContext.Server.MapPath(".") + @"\AuditorSelect\Uploads\" ; if (!Directory.Exists(HttpContext.Server.MapPath(".") + @"\AuditorSelect\Uploads\")) { Directory.CreateDirectory(HttpContext.Server.MapPath(".") + @"\AuditorSelect\Uploads\"); } format.FnF31Two(report, fileLocation); var batch = _repository.Fetch<Parameter>().FirstOrDefault(p => p.Paramname == "BatchNo").Paramvalue; string cpyFile = fileLocation + @"\F" + batch + ".000"; var impersonationCredentials = new ImpersonationCred(); impersonationCredentials.domain = db.Parameter.Where(b => b.Paramname == "ImpersonationDomain").First().Paramvalue; impersonationCredentials.username = db.Parameter.Where(b => b.Paramname == "ImpersonationUser").First().Paramvalue; Parameter impersonationPasswordParam = db.Parameter.Where(b => b.Paramname == "ImpersonationPassword").First(); impersonationCredentials.password = StringCipher.Decrypt(impersonationPasswordParam.Paramvalue, "S41T" + impersonationPasswordParam.Osysdate.ToString() + "Th@tS3cr3tS@uc3"); impersonationCredentials.path = db.Parameter.Where(b => b.Paramname == "ImpersonationPathAudit").First().Paramvalue; //Send //if (!Directory.Exists(Path.GetDirectoryName(@"D:\AuditLetter" + @"\" + Path.GetFileName(cpyFile)))) // Directory.CreateDirectory(Path.GetDirectoryName(@"D:\AuditLetter" + @"\" + Path.GetFileName(cpyFile))); //System.IO.File.Copy(cpyFile, @"D:\AuditLetter" + @"\" + Path.GetFileName(cpyFile), true); Impersonation impersonation = new Impersonation(); impersonation.fnSecureCopy(cpyFile, impersonationCredentials.path + @"\" + Path.GetFileName(cpyFile), impersonationCredentials); model.State = MyEnums.StatusOptions.Approved; model.ReportChecker = User.Identity.GetUserName(); model.Charged = true; _repository.SaveUpdate(model); getVals.LogAudit(User.Identity.GetUserName(), "Approved", Request.UserHostName, "Approved Generated Audit Report. Report Name" + model.ReportName, "Approved", "AuditLetters"); return RedirectToAction("ReportLogIndex"); }
public ActionResult UserApprove(Guid id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } UploadedFormat31File uploadedFormat31File = _repository.Fetch<UploadedFormat31File>().Where(p => p.uploadedFormat31FileId == id).First(); if (uploadedFormat31File == null) { return HttpNotFound(); } ICollection<Format31FileData> fileData = _repository.Fetch<Format31FileData>().Where(f => f.uploadedFormat31FileId == id).OrderBy(f => f.index).ToList(); uploadedFormat31File.fileData = fileData; try { //Check that file has not been sent before //Generate Format 31 File //var fileName = uploadedFormat31File.fileName.ToString(); var fileName = "F" + uploadedFormat31File.batchNumber + "." + uploadedFormat31File.extension; if (!Directory.Exists(HttpContext.Server.MapPath("~/Files/format31/generatedF31"))) { Directory.CreateDirectory(HttpContext.Server.MapPath("~/Files/format31/generatedF31")); } var fullLocalFilePath = Path.Combine(Server.MapPath("~/Files/format31/generatedF31"), fileName + "_" + DateTime.Now.ToFileTime()); string contents = Format31Generator.generateFormat31(uploadedFormat31File); System.IO.File.WriteAllText(fullLocalFilePath, contents); //Fetch send credentials var impersonationCredentials = new ImpersonationCred(); impersonationCredentials.domain = _repository.Fetch<Parameter>().Where(b=>b.Paramname=="ImpersonationDomain").First().Paramvalue; impersonationCredentials.username = _repository.Fetch<Parameter>().Where(b=>b.Paramname=="ImpersonationUser").First().Paramvalue; Parameter impersonationPasswordParam = _repository.Fetch<Parameter>().Where(b=>b.Paramname=="").First(); impersonationCredentials.password = StringCipher.Decrypt(impersonationPasswordParam.Paramvalue, "S41T" + impersonationPasswordParam.Osysdate.ToString() + "Th@tS3cr3tS@uc3"); impersonationCredentials.path = _repository.Fetch<Parameter>().Where(b=>b.Paramname=="ImpersonationPathF31").First().Paramvalue; string fullDestinationPath = Path.Combine(impersonationCredentials.path, fileName); //Send Impersonation impersonation = new Impersonation(); impersonation.fnSecureCopy(fullLocalFilePath, fullDestinationPath, impersonationCredentials); //Update the status of the format31 file and save to db uploadedFormat31File.Cheker = User.Identity.GetUserName(); uploadedFormat31File.StatusOptions = MyEnums.StatusOptions.Approved; //db.UploadedFormat31File.Attach(uploadedFormat31File); db.Entry(uploadedFormat31File).State = EntityState.Modified; db.SaveChanges(); _sharedCls.LogAudit(User.Identity.GetUserName(), "Approve", Request.UserHostName, "Approved Format31 File", "Approval", "Format31"); } catch (Exception e) { _logs.LogError(User.Identity.GetUserName(), "RegisterUser", "Format31.UserApprove: " + e.Message, Request.ServerVariables["REMOTE_ADDR"], HttpContext.Server.MapPath("."), "Format31"); System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath("~/errorLOG.txt"), System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite); System.IO.StreamWriter s = new System.IO.StreamWriter(fs); s.BaseStream.Seek(0, System.IO.SeekOrigin.End); s.WriteLine("ERROR DATE: " + System.DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture) + " \nERROR MESSAGE: " + e.Message + "\nSOURCE: " + e.Source + "\nFORM NAME: " + System.Web.HttpContext.Current.Request.Url.ToString() + "\nQUERYSTRING: " + Request.QueryString.ToString() + "\nTARGETSITE: " + e.TargetSite.ToString() + "\nSTACKTRACE: " + e.StackTrace + System.Diagnostics.EventLogEntryType.Error); s.WriteLine("-------------------------------------------------------------------------------------------------------------"); s.Close(); } return RedirectToAction("ApproveIndex"); }
private void fnHandoffs(StringBuilder entry, string branch, string filepath) { string date = DateTime.Now.ToString("yyyyMMdd"); filepath += date + @"\IF_PEBS_RFRTUPL_" + branch + DateTime.Now.ToString("yyMMdd.DAT"); if (File.Exists(filepath)) File.Delete(filepath); if (!Directory.Exists(Path.GetDirectoryName(filepath))) Directory.CreateDirectory(Path.GetDirectoryName(filepath)); FileStream fs = new FileStream(filepath, FileMode.CreateNew, FileAccess.ReadWrite); using (StreamWriter sw = new StreamWriter(fs)) { sw.Write(entry); } var impersonationCredentials = new ImpersonationCred(); impersonationCredentials.domain = db.Parameter.Where(b => b.Paramname == "ImpersonationDomain").First().Paramvalue; impersonationCredentials.username = db.Parameter.Where(b => b.Paramname == "ImpersonationUser").First().Paramvalue; Dev.Tech.Db.Models.SysConfig.Parameter impersonationPasswordParam = db.Parameter.Where(b => b.Paramname == "ImpersonationPassword").First(); impersonationCredentials.password = StringCipher.Decrypt(impersonationPasswordParam.Paramvalue, "S41T" + impersonationPasswordParam.Osysdate.ToString() + "Th@tS3cr3tS@uc3"); impersonationCredentials.path = db.Parameter.Where(b => b.Paramname == "ImpersonationPathPool").First().Paramvalue; //Send //if (!Directory.Exists(Path.GetDirectoryName(@"D:\PoolFile" + @"\" + Path.GetFileName(filepath)))) // Directory.CreateDirectory(Path.GetDirectoryName(@"D:\PoolFile" + @"\" + Path.GetFileName(filepath))); //File.Copy(filepath, @"D:\PoolFile" + @"\" + Path.GetFileName(filepath), true); Impersonation impersonation = new Impersonation(); impersonation.fnSecureCopy(filepath, impersonationCredentials.path + @"\" + Path.GetFileName(filepath), impersonationCredentials); }