public static Party GetPartyByID(string id) { int partyID = 0; int.TryParse(id, out partyID); ILibrary <Party> lib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); return(lib.GetByID(partyID.ToString())); }
public JsonResult _SaveCustomerImages(string scaleId, string partyId) { try { if (!string.IsNullOrEmpty(partyId)) { // Get party PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); smART.ViewModel.Party party = partyLib.GetByID(partyId); if (party != null) { FilelHelper fileHelper = new FilelHelper(); string filePath; // Save Customer Image if (!string.IsNullOrEmpty(party.PhotoRefId)) { filePath = fileHelper.GetFilePathByFileRefId(party.PhotoRefId); if (System.IO.File.Exists(filePath)) { Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath); SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Customer), EnumAttachmentRefType.Customer, FileFormat.jpeg); } } // Signature Image if (!string.IsNullOrEmpty(party.SignatureImageRefId)) { filePath = fileHelper.GetFilePathByFileRefId(party.SignatureImageRefId); if (System.IO.File.Exists(filePath)) { Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath); SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Signature), EnumAttachmentRefType.Signature, FileFormat.bmp); } } // Thumb Image if (!string.IsNullOrEmpty(party.ThumbImage1RefId)) { filePath = fileHelper.GetFilePathByFileRefId(party.ThumbImage1RefId); if (System.IO.File.Exists(filePath)) { Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath); SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Thumbprint1), EnumAttachmentRefType.Thumbprint1, FileFormat.jpg); } } // License Image if (!string.IsNullOrEmpty(party.LicenseImageRefId)) { filePath = fileHelper.GetFilePathByFileRefId(party.LicenseImageRefId); if (System.IO.File.Exists(filePath)) { Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath); SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.DriverLicense), EnumAttachmentRefType.DriverLicense, FileFormat.jpg); } } // Vehicle Image if (!string.IsNullOrEmpty(party.VehicleImageRegId)) { filePath = fileHelper.GetFilePathByFileRefId(party.VehicleImageRegId); if (System.IO.File.Exists(filePath)) { Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath); SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Vehicle), EnumAttachmentRefType.Vehicle, FileFormat.jpg); } } // Cash Card Image if (!string.IsNullOrEmpty(party.CashCardImageRefId)) { filePath = fileHelper.GetFilePathByFileRefId(party.CashCardImageRefId); if (System.IO.File.Exists(filePath)) { Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath); SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.CashCard), EnumAttachmentRefType.CashCard, FileFormat.jpg); } } } } return(Json(new { Sucess = "True" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Sucess = ex.Message }, JsonRequestBehavior.AllowGet)); } }
private void SaveThumbScannerAttachment(int Id, byte[] data, string fileName, EnumAttachmentRefType refType, FileFormat fileFormat, bool updateParty = true) { Guid guid = SaveFile(data, string.Format("{0}.{1}", fileName, fileFormat.ToString())); ScaleAttachments attachments = new ScaleAttachments(); attachments.Document_Name = string.Format("{0}.{1}", fileName, fileFormat.ToString());// "Thumb-Image.jpeg"; attachments.Document_RefId = guid; attachments.Document_Size = data.LongLength; attachments.Document_Title = "Thumb-Image"; attachments.Document_Type = "jpeg"; attachments.Ref_Type = (int)refType; attachments.Updated_By = User.Identity.Name; attachments.Created_By = User.Identity.Name; attachments.Created_Date = DateTime.Now; attachments.Last_Updated_Date = DateTime.Now; attachments.Parent = new Scale { ID = Id }; string destinationPath; string sourcePath; FilelHelper fileHelper = new FilelHelper(); destinationPath = fileHelper.GetSourceDirByFileRefId(attachments.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString()); sourcePath = fileHelper.GetTempSourceDirByFileRefId(attachments.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString()); attachments.Document_Path = fileHelper.GetFilePath(sourcePath); if (Id > 0) { fileHelper.MoveFile(attachments.Document_Name, sourcePath, destinationPath); ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); attachments.Document_Name = string.Format("{0}.{1}", fileName, "jpg"); ScaleAttachments scaleAttachment = ScaleLibrary.Add(attachments); if (updateParty) { Scale scale = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(Id.ToString(), new string[] { "Party_ID" }); PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); Party party = partyLib.GetByID(scale.Party_ID.ID.ToString()); if (party != null) { party.PhotoRefId = scaleAttachment.Document_RefId.ToString(); partyLib.Modify(party); } } } else { if (Session["ScaleAttachments"] == null) { Session["ScaleAttachments"] = new List <ScaleAttachments>(); } IList <ScaleAttachments> iList = (IList <ScaleAttachments>)Session["ScaleAttachments"]; iList.Add(attachments); } }
public string SaveTicketImage(String scaleId, string documentType) { var docfiles = new List <string>(); try { int intScaleId = Convert.ToInt32(scaleId); if (intScaleId <= 0) { throw new Exception("Invalid ticket id."); } int intDocType = Convert.ToInt32(documentType); string fileName = CommonHelper.GetFileNameByDocType(intDocType); if (string.IsNullOrEmpty(fileName)) { throw new Exception("Invalid document type."); } var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { // Get scale Scale scale = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(scaleId, new string[] { "Party_ID" }); if (scale == null) { throw new Exception("Given scale id not found in database."); } FilelHelper fileHelper = new FilelHelper(); foreach (string file in httpRequest.Files) { // Save file string docRefID = Guid.NewGuid().ToString(); var destinationPath = fileHelper.GetSourceDirByFileRefId(docRefID); // Path.Combine(Configuration.GetsmARTTempDocPath(), docRefID); fileHelper.CreateDirectory(destinationPath); var postedFile = httpRequest.Files[file]; postedFile.SaveAs(Path.Combine(destinationPath, fileName)); docfiles.Add(docRefID); // Add attachment ScaleAttachments attachments = new ScaleAttachments(); attachments.Document_Name = fileName; attachments.Document_RefId = new Guid(docRefID); attachments.Document_Size = 0; attachments.Document_Title = fileName; attachments.Document_Type = "jpeg"; attachments.Ref_Type = intDocType; attachments.Updated_By = User.Identity.Name; attachments.Created_By = User.Identity.Name; attachments.Created_Date = DateTime.Now; attachments.Last_Updated_Date = DateTime.Now; attachments.Parent = new Scale { ID = intScaleId }; attachments.Document_Path = destinationPath; ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); attachments.Document_Name = fileName; ScaleAttachments scaleAttachment = ScaleLibrary.Add(attachments); // Update file ref in party master if (scale.Party_ID != null && scale.Party_ID.ID > 0) { PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); Party party = partyLib.GetByID(scale.Party_ID.ID.ToString()); if (party != null) { SetPartyImageRefByDocType(intDocType, scaleAttachment.Document_RefId.ToString(), party); partyLib.Modify(party); } } } } } catch (Exception ex) { //string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicketImage", ex.Message, ex.StackTrace.ToString()); ExceptionHandler.HandleException(ex, "An error occured in SaveTicketImage utils."); //smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service"); } return(docfiles.FirstOrDefault()); }