protected override void DeleteChildEntities(string[] childEntityList, string parentID) { foreach (string ChildEntity in childEntityList) { switch (ChildEntity) { #region /* Case Statements - All child grids */ case "ScaleDetails": if (Convert.ToInt32(parentID) > 0) { ScaleDetailsLibrary ScaleDetailsLibrary = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleDetails> resultList = ScaleDetailsLibrary.GetAllByParentID(Convert.ToInt32(parentID)); foreach (ScaleDetails scaleDetails in resultList) { ScaleDetailsLibrary.Delete(scaleDetails.ID.ToString()); } } break; case "ScaleNotes": if (Convert.ToInt32(parentID) > 0) { ScaleNotesLibrary ScaleNotesLibrary = new ScaleNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleNotes> resultList = ScaleNotesLibrary.GetAllByParentID(Convert.ToInt32(parentID)); foreach (ScaleNotes ScaleNote in resultList) { ScaleNotesLibrary.Delete(ScaleNote.ID.ToString()); } } break; case "ScaleAttachments": if (Convert.ToInt32(parentID) > 0) { ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleAttachments> resultList = ScaleLibrary.GetAllByParentID(Convert.ToInt32(parentID)); foreach (ScaleAttachments scaleAttachment in resultList) { ScaleLibrary.Delete(scaleAttachment.ID.ToString()); } } break; //case "ScaleIDCardAttachments": // if (Convert.ToInt32(parentID) > 0) { // ScaleIDCardAttachmentsLibrary ScaleLibrary = new ScaleIDCardAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); // IEnumerable<ScaleIDCardAttachments> resultList = ScaleLibrary.GetAllByParentID(Convert.ToInt32(parentID)); // foreach (ScaleIDCardAttachments scaleAttachment in resultList) { // ScaleLibrary.Delete(scaleAttachment.ID.ToString()); // } // } //break; #endregion } } }
public IEnumerable <ScaleAttachments> GetTicketAttachmentsByTicketId(int ticketId) { IEnumerable <ScaleAttachments> ticketAttachments = _scaleAttachmentLib.GetAllByParentID(ticketId, new string[] { "Parent" }); return(ticketAttachments); }
public ActionResult SendEmail(string id) { string destinationFilePath = string.Empty; FilelHelper fileHelper = new FilelHelper(); try { if (string.IsNullOrEmpty(id)) { throw new Exception("Email send failed due to Container# not found."); } ContainerLibrary containerLib = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); Container container = containerLib.GetByID(id, new string[] { "Booking.Sales_Order_No.Party" }); if (container == null || container.Booking == null || container.Booking.Sales_Order_No == null || container.Booking.Sales_Order_No.Party == null) { throw new Exception("Email send failed."); } IEnumerable <Contact> contacts = Helpers.ContactHelper.GetEmailContactsByPartyId(container.Booking.Sales_Order_No.Party.ID); if (contacts.Count() <= 0) { throw new Exception("There is no email contact exists."); } NotificationDefinition notDef = new NotificationDefinition(); notDef.ToRecipients = new System.Net.Mail.MailAddressCollection(); foreach (var item in contacts) { notDef.ToRecipients.Add(new System.Net.Mail.MailAddress(item.Email, item.ListText)); } EmployeeHelper employeeHelper = new EmployeeHelper(); Employee employee = employeeHelper.GetEmployeeByUsername(System.Web.HttpContext.Current.User.Identity.Name); if (employee == null || string.IsNullOrEmpty(employee.Email) || string.IsNullOrEmpty(employee.Email_Password)) { throw new Exception("Sender email and password is required."); } ScaleLibrary scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); Scale scale = scaleLib.GetScalesByContainerId(container.ID); ScaleAttachmentsLibrary scaleAttachLib = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleAttachments> scaleAttachments = scaleAttachLib.GetAllByParentID(scale.ID); if (scaleAttachments == null || scaleAttachments.Count() <= 0) { throw new Exception("There is no attachment found."); } destinationFilePath = Path.Combine(Path.GetTempPath(), container.ID.ToString()); fileHelper.CreateDirectory(destinationFilePath); fileHelper.DeleteFiles(destinationFilePath); string imageFilePath = Path.Combine(destinationFilePath, "Images"); fileHelper.CreateDirectory(imageFilePath); string zipFilePath = Path.Combine(destinationFilePath, container.ID.ToString() + ".zip"); foreach (var item in scaleAttachments) { string sourceFilePath = fileHelper.GetFilePathByFileRefId(item.Document_RefId.ToString()); string imageFileFullPath = Path.Combine(imageFilePath, item.Document_Name); System.IO.File.Copy(sourceFilePath, imageFileFullPath); } new smART.Common.FilelHelper().CreateZip(imageFilePath, zipFilePath); if (!fileHelper.FileExits(zipFilePath)) { throw new Exception("There is no attachment found."); } string xslPath = Path.Combine(ConfigurationHelper.GetsmARTXslPath(), "ContainerEmailBody.xslt"); string smtpAddress = ConfigurationHelper.GetsmARTSMTPServer(); notDef.Attachments = new List <System.Net.Mail.Attachment>(); notDef.Attachments.Add(new System.Net.Mail.Attachment(zipFilePath)); notDef.DeliveryType = EnumNotificationDeliveryType.Email; notDef.FormatType = EnumFormatType.HTML; notDef.Sender = new System.Net.Mail.MailAddress(employee.Email, employee.Emp_Name); notDef.SMTPServer = smtpAddress; notDef.SMTPServerCredentialID = employee.Email; notDef.SMTPServerCredentialPwd = employee.Email_Password; notDef.Subject = "Booking#/Container#: " + container.Booking.Booking_Ref_No + "/" + container.Container_No; NotificationHelper.StartNotificationWF(id, container.Booking.Sales_Order_No.Party.Party_Name, PartyHelper.GetOrganizationName(), employee.Emp_Name, notDef, xslPath, NotificationWFCompleted, container.Booking.Booking_Ref_No, container.Booking.Sales_Order_No.ID.ToString()); //return Display(command, container); if (_sendMail == true) { return(Json(new { Sucess = "Email send sucessfully." }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Sucess = "Email send failed." }, JsonRequestBehavior.AllowGet)); } //return Json(new { Sucess = "Email send sucessfully." }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { //var script = @"ShowAlertMessage(""Send mail failed"");"; //return JavaScript(script); return(Json(new { Sucess = ex.Message }, JsonRequestBehavior.AllowGet)); } finally { //fileHelper.DeleteDirectory(destinationFilePath); } }