public ActionResult Upload(int taskId, HttpPostedFileBase files) { var session = DataConfig.GetSession(); var task = session.Load <Domain.Task>(taskId); var attachment = new Domain.Attachment { Task = task, FileName = files.FileName, ContentType = files.ContentType, Guid = Guid.NewGuid() }; var path = Path.Combine( Path.Combine(Server.MapPath("~"), Domain.Attachment.AttachmentsStorageDirectory), attachment.Guid.ToString()); files.SaveAs(path); task.Attachments.Add(attachment); session.SaveOrUpdate(attachment); session.Transaction.Commit(); return(Json(new { Id = attachment.Id, FileName = attachment.FileName })); }
public List<Domain.Email> GetMail() { bool getAllMail = Config["GetMailType"].Equals("GETALLMAIL123")? true : false; List<Domain.Email> emails = new List<Domain.Email>(); try { using (LotusNotesMailClient client = new LotusNotesMailClient()) { LotusNotesMailService.Email[] emailsLotusNotes = client.GetMail(getAllMail); if (emailsLotusNotes != null) { CurrentMailAccessIndicator = MailAccessIndicator.MailChecked; foreach (var emailLotusNotes in emailsLotusNotes) { Domain.Email localEmail = new Domain.Email(); localEmail.From = emailLotusNotes.From; localEmail.To = emailLotusNotes.To; localEmail.Subject = emailLotusNotes.Subject; localEmail.Body = emailLotusNotes.Body; if (emailLotusNotes.Attachments != null && emailLotusNotes.Attachments.Length > 0) { try { using (LotusNotesMailClient clientFetchAttachments = new LotusNotesMailClient()) { emailLotusNotes.Attachments = clientFetchAttachments.GetEmailAttachments(emailLotusNotes); foreach (LotusNotesMailService.Attachment attachment in emailLotusNotes.Attachments) { Domain.Attachment localAttachment = new Domain.Attachment(); localAttachment.FileName = attachment.FileName; localAttachment.FilePath = attachment.FilePath; localAttachment.Content = attachment.Content; localEmail.Attachments.Add(localAttachment); } } } catch (Exception e) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Log(LogLevel.Error, "Exception occurred when getting attachments for the email", e); CurrentMailAccessIndicator = MailAccessIndicator.MailFetchError; } } emails.Add(localEmail); CurrentMailAccessIndicator = MailAccessIndicator.MailFetched; } } } } catch (CommunicationException ce) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Log(LogLevel.Error, "Exception occurred when connecting to the Lotus Notes mail server", ce); CurrentMailAccessIndicator = MailAccessIndicator.LoginError; } catch (Exception e) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Log(LogLevel.Error, "Exception occurred when retrieving mail from Lotus Notes", e); CurrentMailAccessIndicator = MailAccessIndicator.MailFetchError; } return emails; }