internal static MailUser MapToMailUser(MAIL_SENDERS dr, MailServer s, List <Folder> l) { MailUser u = null; if (s != null) { u = new MailUser(s); } else { u = new MailUser(); } u.UserId = dr.ID_SENDER; u.IdResponsabile = (decimal)dr.ID_RESPONSABILE; u.Casella = dr.MAIL; u.Dominus = (s == null) ? "" : s.Dominus; u.EmailAddress = dr.MAIL; u.LoginId = dr.USERNAME; u.Password = dr.PASSWORD; u.Folders = l; if (dr.FLG_MANAGED != null) { u.FlgManaged = int.Parse(dr.FLG_MANAGED); u.FlgManagedInsert = (dr.FLG_MANAGED == "0") ? false : true; } else { u.FlgManagedInsert = false; } return(u); }
public void Insert(ActiveUp.Net.Mail.DeltaExt.MailUser entity) { try { using (FAXPECContext dbcontext = new FAXPECContext()) { MAIL_SENDERS s = new MAIL_SENDERS(); s.USERNAME = entity.LoginId; s.ID_MAILSERVER = entity.Id; s.ID_RESPONSABILE = entity.IdResponsabile; s.PASSWORD = entity.Password; // s.ID_RESPONSABILE = 1; s.FLG_MANAGED = (entity.FlgManaged == 0) ? "0" : "1"; s.MAIL = entity.EmailAddress.ToLower().Trim(); dbcontext.MAIL_SENDERS.Add(s); int resp = dbcontext.SaveChanges(); if (resp == 1) { entity.UserId = dbcontext.MAIL_SENDERS.OrderByDescending(c => c.ID_SENDER).FirstOrDefault().ID_SENDER; } } } catch (Exception ex) { if (!ex.GetType().Equals(typeof(ManagedException))) { ManagedException mEx = new ManagedException(ex.Message, "ERR_ACC_004", string.Empty, string.Empty, ex.InnerException); ErrorLogInfo err = new ErrorLogInfo(mEx); err.objectID = entity.Id.ToString(); log.Error(err); } } }
public void Update(ActiveUp.Net.Mail.DeltaExt.MailUser entity) { try { using (FAXPECContext dbcontext = new FAXPECContext()) { MAIL_SENDERS m = dbcontext.MAIL_SENDERS.Where(x => x.ID_SENDER == entity.UserId).First(); if (m != null) { m.PASSWORD = entity.Password; m.MAIL = entity.EmailAddress; m.ID_RESPONSABILE = entity.IdResponsabile; m.ID_MAILSERVER = entity.Id; m.USERNAME = entity.LoginId; m.FLG_MANAGED = (entity.FlgManaged == 0) ? "0" : "1"; dbcontext.SaveChanges(); } } } catch (Exception ex) { if (!ex.GetType().Equals(typeof(ManagedException))) { ManagedException mEx = new ManagedException(ex.Message, "ERR_ACC_005", string.Empty, string.Empty, ex.InnerException); ErrorLogInfo err = new ErrorLogInfo(mEx); err.objectID = entity.Id.ToString(); log.Error(err); } } }
public IList <MailUser> GetUserByServerAndUsername(decimal idServer, string userName) { List <MailUser> lUser = null; using (FAXPECContext dbcontext = new FAXPECContext()) { var mailsender = dbcontext.MAIL_SENDERS.Where(x => x.ID_MAILSERVER == idServer && x.USERNAME.ToUpper() == userName.ToUpper()).FirstOrDefault(); if (mailsender != null) { try { lUser = new List <MailUser>(); MAIL_SENDERS m = dbcontext.MAIL_SENDERS.Where(x => x.ID_MAILSERVER == idServer).FirstOrDefault(); int idmailserver = (int)m.ID_MAILSERVER; MAILSERVERS ms = dbcontext.MAILSERVERS.Where(x => x.ID_SVR == idmailserver).FirstOrDefault(); int idmailuser = (int)mailsender.ID_SENDER; MailServer s = AutoMapperConfiguration.FromMailServersToModel(ms); if (idmailuser != 0) { List <Folder> l = GetMailFolders(idmailuser); lUser.Add(DaoSQLServerDBHelper.MapToMailUser(mailsender, s, l)); } } catch { lUser = null; throw; } } else { return(lUser); } } return(lUser); }