Beispiel #1
0
        public static List <MailEntity> FindByMailAccount(MailAccount mailAccount, ISession session)
        {
            List <MailEntity> foundMails = (List <MailEntity>)session.CreateCriteria <MailEntity>()
                                           .Add(Restrictions.Eq("MailAccountEntity", mailAccount.Entity))
                                           .List <MailEntity>();

            return(foundMails);
        }
Beispiel #2
0
        public static void SendResetPasswordMail(User user, String newPassword, ISession session)
        {
            MailAccount mailAccount = MailAccount.FindMainMailAccount(user.Entity.Username, session);

            if (mailAccount == null)
            {
                throw new Exception("Usuario: " + user.Entity.Username + " no posee cuenta primaria.");
            }
            Sender.SendResetPasswordMail(user.Entity.Username, mailAccount.Entity.Address, newPassword);
        }
Beispiel #3
0
 public void ValidateCredentials()
 {
     using (ISession session = NHibernateManager.OpenSession())
     {
         MailAccount correctMailAccount = MailAccount.FindByAddress(this.Entity.Address, session, false);
         if (!CryptoHelper.PasswordsMatch(correctMailAccount.Entity.Password, this.Entity.Password))
         {
             throw new InvalidAuthenticationException("Las credenciales ingresadas no son validas, usuario:" + this.Entity.Address);
         }
     }
 }
Beispiel #4
0
        } //Safe

        public void FetchAndSaveMails(Label label, Int64 fromUid, Int64 toUid, ref Int32 amountOfMails)
        {
            List <Mail> mails = this.MyFetcher.GetMailsBetweenUID(label.Entity.Name, (int)fromUid, (int)toUid);

            foreach (Mail mail in mails)
            {
                mail.Entity.MailAccountEntity = this.Entity;
            }
            MailAccount.Save(mails);
            amountOfMails = mails.Count;
        }
Beispiel #5
0
 public void AddAccount(MailAccount mailAccount)
 {
     if (!this.mailAccounts.Any(x => x.Entity.Address == mailAccount.Entity.Address)) //si no lo tiene
     {
         this.mailAccounts.Add(mailAccount);
     }
     else //si ya lo tiene que lo actualice
     {
         MailAccount newMailaccount = this.mailAccounts.Single(x => x.Entity.Address == mailAccount.Entity.Address);
         newMailaccount = mailAccount;
     }
 }
Beispiel #6
0
        public virtual void SaveOrUpdate(ISession session)
        {
            MailAccount oldAccount = MailAccount.FindByAddress(this.Entity.Address, session, false);

            if (oldAccount != null)
            {
                oldAccount.Entity.User          = this.Entity.User;
                oldAccount.Entity.Address       = this.Entity.Address;
                oldAccount.Entity.Password      = this.Entity.Password;
                oldAccount.Entity.IsMainAccount = this.Entity.IsMainAccount;
                oldAccount.Entity.Active        = this.Entity.Active;
                this.Entity = oldAccount.Entity;
            }
            session.SaveOrUpdate(this.Entity);
        }
Beispiel #7
0
        public static Label FindByName(MailAccount mailAcccount, String labelName, ISession session)
        {
            LabelEntity labelEntity;

            labelEntity = session.CreateCriteria <LabelEntity>()
                          .Add(Restrictions.Eq("MailAccountEntity", mailAcccount.Entity))
                          .Add(Restrictions.Eq("Name", labelName))
                          .Add(Restrictions.Eq("Active", true))
                          .UniqueResult <LabelEntity>();

            if (labelEntity == null)
            {
                return(null);
            }

            return(new Label(labelEntity));
        }
Beispiel #8
0
        public MailAccount Clone()
        {
            MailAccount       mailAccountClone;
            MailAccountEntity entity;

            using (ISession session = NHibernateManager.OpenSession())
            {
                entity           = MailAccount.FindByAddress(this.Entity.Address, session, false).Entity;
                mailAccountClone = new MailAccount(entity);

                if (this.IsConnected())
                {
                    mailAccountClone.ConnectFull(session);
                }
                session.Close();
            }
            return(mailAccountClone);
        }
Beispiel #9
0
        public static Label FindBySystemName(MailAccount account, String systemName, ISession session)
        {
            LabelEntity labelEntity;

            try
            {
                labelEntity = session.CreateCriteria <LabelEntity>()
                              .Add(Restrictions.Eq("MailAccountEntity", account.Entity))
                              .Add(Restrictions.Eq("SystemName", systemName))
                              .Add(Restrictions.Eq("Active", true))
                              .UniqueResult <LabelEntity>();
                return(new Label(labelEntity));
            }
            catch (NHibernate.HibernateException e)
            {
                throw new NotUniqueResultException(e, "Cuenta: " + account.Entity.Address + " ,SystemName Label: " + systemName);
            }
        }
Beispiel #10
0
        public static void ColorLabel(LabelEntity labelToColor, MailAccount labelAccount, User currentUser, ISession session)
        {
            if (currentUser != null)
            {
                IList <MailAccount> currentMailAccounts = currentUser.GetAccounts();
                List <LabelEntity>  availableLabels     = new List <LabelEntity>();

                foreach (MailAccount mailAccount in currentMailAccounts)
                {
                    availableLabels.AddRange(Label.FindByAccount(mailAccount.Entity, session));
                }

                //si alguna de las cuentas ya tiene un label con el mismo nombre
                if (availableLabels.Any(x => x.SystemName == null && x.Name == labelToColor.Name))
                {
                    labelToColor.Color = availableLabels.Where(x => x.SystemName == null && x.Name == labelToColor.Name).ToList()[0].Color;
                    return;
                }
            }
            labelToColor.Color = Label.GetNextColor(labelAccount.Entity, session);
        }