public HttpResponseMessage GetSottoTitoli(string idtitolo, int?page, int?start, int?limit) { TitolarioService <SendMail.Model.SottoTitolo> ts = new TitolarioService <SendMail.Model.SottoTitolo>(); TitoliModel model = new TitoliModel(); IList <SendMail.Model.SottoTitolo> sottotitoli = new List <SendMail.Model.SottoTitolo>(); try { if (CacheManager <List <SendMail.Model.Titolo> > .exist(CacheKeys.ALL_SUBTITLES)) { sottotitoli = CacheManager <List <SendMail.Model.SottoTitolo> > .get(CacheKeys.ALL_SUBTITLES, VincoloType.BACKEND); } else { sottotitoli = (List <SendMail.Model.SottoTitolo>)ts.FindByTitolo(int.Parse(idtitolo)); } model.success = "true"; model.SottoTitoliList = sottotitoli.ToList(); model.Totale = sottotitoli.Count.ToString(); } catch (Exception ex) { if (!ex.GetType().Equals(typeof(ManagedException))) { ErrorLogInfo error = new ErrorLogInfo(); error.freeTextDetails = ex.Message; error.logCode = "ERR_T002"; error.loggingAppCode = "PEC"; error.loggingTime = System.DateTime.Now; error.uniqueLogID = System.DateTime.Now.Ticks.ToString(); log.Error(error); model.message = ex.Message; model.success = "false"; } else { model.message = ex.Message; model.success = "false"; } return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model)); } return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model)); }
public HttpResponseMessage Comunicazione(FormDataCollection formsValues) { string regexMail = RegexUtils.EMAIL_REGEX.ToString(); TitoliModel model = new TitoliModel(); try { List <ComAllegato> allegati = new List <ComAllegato>(); SendMail.Model.ComunicazioniMapping.Comunicazioni comun = new SendMail.Model.ComunicazioniMapping.Comunicazioni(); string destinatario = formsValues["Destinatario"]; string conoscenza = formsValues["Conoscenza"]; string bcc = formsValues["BCC"]; string oggetto = formsValues["Oggetto"]; string testoMail = formsValues["TestoMail"]; string titolo = formsValues["Titolo"]; string sottotitolo = formsValues["SottoTitolo"]; string userid = formsValues["SenderMail"]; if (SessionManager <Dictionary <string, DTOFileUploadResult> > .exist(SessionKeys.DTO_FILE)) { Dictionary <string, DTOFileUploadResult> dictDto = SessionManager <Dictionary <string, DTOFileUploadResult> > .get(SessionKeys.DTO_FILE); List <DTOFileUploadResult> dto = (List <DTOFileUploadResult>)dictDto.Values.ToList(); foreach (DTOFileUploadResult d in dto) { SendMail.Model.ComunicazioniMapping.ComAllegato allegato = new SendMail.Model.ComunicazioniMapping.ComAllegato(); allegato.AllegatoExt = d.Extension; allegato.AllegatoFile = d.CustomData; allegato.AllegatoName = d.FileName; allegato.AllegatoTpu = ""; allegato.FlgInsProt = AllegatoProtocolloStatus.FALSE; allegato.FlgProtToUpl = AllegatoProtocolloStatus.FALSE; allegati.Add(allegato); } } comun.ComAllegati = allegati; string[] destinatari = destinatario.Split(';'); for (int i = 0; i < destinatari.Length; i++) { var match = Regex.Match(destinatari[i], regexMail, RegexOptions.IgnoreCase); if (!match.Success) { model.success = "false"; model.message = "Attenzione mail destinatario non valida"; return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model)); } } // gestione destinatari ContactsApplicationMapping c = new ContactsApplicationMapping { Mail = destinatario, IdSottotitolo = long.Parse(sottotitolo), IdTitolo = long.Parse(titolo) }; Collection <ContactsApplicationMapping> en = new Collection <ContactsApplicationMapping>(); en.Add(c); if (conoscenza != string.Empty) { string[] conoscenze = conoscenza.Split(';'); for (int i = 0; i < conoscenze.Length; i++) { var match = Regex.Match(conoscenze[i], regexMail, RegexOptions.IgnoreCase); if (!match.Success) { model.success = "false"; model.message = "Attenzione mail conoscenza non valida"; return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model)); } } ContactsApplicationMapping c1 = new ContactsApplicationMapping { Mail = conoscenza, IdSottotitolo = long.Parse(sottotitolo), IdTitolo = long.Parse(titolo) }; Collection <ContactsApplicationMapping> en1 = new Collection <ContactsApplicationMapping>(); en1.Add(c1); comun.SetMailDestinatari(en1, AddresseeType.CC); } if (bcc != string.Empty) { string[] bccs = bcc.Split(';'); for (int i = 0; i < bcc.Length; i++) { var match = Regex.Match(bccs[i], regexMail, RegexOptions.IgnoreCase); if (!match.Success) { model.success = "false"; model.message = "Attenzione mail destinatario nascosto non valido"; return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model)); } } ContactsApplicationMapping c2 = new ContactsApplicationMapping { Mail = bcc, IdSottotitolo = long.Parse(sottotitolo), IdTitolo = long.Parse(titolo) }; Collection <ContactsApplicationMapping> en2 = new Collection <ContactsApplicationMapping>(); en2.Add(c2); comun.SetMailDestinatari(en2, AddresseeType.CCN); } comun.SetMailDestinatari(en, AddresseeType.TO); // gestione body email MailContent content = new MailContent(); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); string html = testoMail; HtmlAgilityPack.HtmlNode body = null; if (string.IsNullOrEmpty(html) == false) { doc.LoadHtml(html); doc.OptionAutoCloseOnEnd = true; doc.OptionFixNestedTags = true; body = doc.DocumentNode.Descendants() .Where(n => n.Name.Equals("body", StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); } var ele = new HtmlAgilityPack.HtmlNode(HtmlAgilityPack.HtmlNodeType.Element, doc, 0); ele.Name = "div"; ele.InnerHtml = testoMail; content.MailSubject = oggetto; content.MailText = ele.OuterHtml; // gestione sender MailServerConfigFacade mailSCF = MailServerConfigFacade.GetInstance(); MailUser mailuser = mailSCF.GetUserByUserId(decimal.Parse(userid)); content.MailSender = mailuser.EmailAddress; c.IdTitolo = long.Parse(titolo); c.IdSottotitolo = long.Parse(sottotitolo); comun.UtenteInserimento = MySecurityProvider.CurrentPrincipal.MyIdentity.UserName; comun.MailComunicazione = content; // da scommentare comun.FolderTipo = "O"; comun.FolderId = 2; ComunicazioniService com = new ComunicazioniService(); com.InsertComunicazione(comun); model.success = "true"; SessionManager <Dictionary <string, DTOFileUploadResult> > .del(SessionKeys.DTO_FILE); } catch (Exception ex) { if (ex.GetType() != typeof(ManagedException)) { ManagedException mEx = new ManagedException("Errore invio nuova mail. Dettaglio: " + ex.Message + "StackTrace: " + ((ex.StackTrace != null) ? ex.StackTrace.ToString() : " vuoto "), "ERR317", string.Empty, string.Empty, ex.InnerException); ErrorLogInfo err = new ErrorLogInfo(mEx); log.Error(err); model.success = "false"; model.message = ex.Message; return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model)); } } return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model)); }