public Int32 SaveDraftOld(dtoMailMessage eMail) { try { Mail mail = Mapper.Map <Mail>(eMail); PrepareDraftMailData(mail); if (eMail.MailId == 0) { dataContext.Mails.Add(mail); int retValue = dataContext.SaveChanges(); dataContext = new MailManagerDBConnection(); } else { dataContext.Entry(mail).State = EntityState.Modified; Int32 retval = dataContext.SaveChanges(); dataContext = new MailManagerDBConnection(); } return(mail.MailId); } catch (Exception ex) { throw ex; } }
public dtoMailMessage SaveDraft(dtoMailMessage eMail) { using (DbContextTransaction transaction = dataContext.Database.BeginTransaction()) { try { Mail mail = Mapper.Map <Mail>(eMail); PrepareDraftMailData(mail); if (eMail.MailId == 0) { dataContext.Mails.Add(mail); int retValue = dataContext.SaveChanges(); eMail.MailId = mail.MailId; if (eMail.AttachmentsList.Count > 0 && eMail.AttachmentsList[0].MailId != mail.MailId) { var sourceMailId = Convert.ToInt32(eMail.AttachmentsList[0].MailId); for (Int32 i = 0; i < eMail.AttachmentsList.Count; i++) { eMail.AttachmentsList[i].AttachmentId = 0; eMail.AttachmentsList[i].MailId = mail.MailId; MailAttachment attch = Mapper.Map <MailAttachment>(eMail.AttachmentsList[i]); dataContext.MailAttachments.Add(attch); dataContext.SaveChanges(); eMail.AttachmentsList[i].AttachmentId = attch.AttachmentId; } fileService.CopyFiles(sourceMailId, mail.MailId); } } else { dataContext.Entry(mail).State = EntityState.Modified; Int32 retval = dataContext.SaveChanges(); } transaction.Commit(); return(eMail); } catch (Exception ex) { transaction.Rollback(); dataContext = new MailManagerDBConnection(); throw ex; } } }
public Int32 SaveAttachment(dtoMailAttachment eMailAttach) { try { MailAttachment attch = Mapper.Map <MailAttachment>(eMailAttach); dataContext.MailAttachments.Add(attch); int retValue = dataContext.SaveChanges(); dataContext = new MailManagerDBConnection(); return(attch.AttachmentId); } catch (Exception ex) { throw ex; } }
public UserAccountsService() { this.dataContext = new MailManagerDBConnection(); }