private string RegisterSession(Account account)
        {
            if(_repository.GetSession(account) != null)
                _repository.DeleteSession(account);

            return _repository.RegisterSession(account);
        }
        public string GetSession(Account account)
        {
            return EF.Execute("MySqlRepository.VerifySession",
                ctx =>
                    {
                        var sessions = (from s in ctx.sessions
                                       where s.accountId == account.Id
                                       select s.hash).ToList();

                        return sessions.Count == 0 ? null : sessions[0];

                    }, null);
        }
 public string RegisterSession(Account account)
 {
     return EF.Execute("MySqlRepository.RegisterSession",
         ctx =>
             {
                 var hash = account.Hash();
                 ctx.sessions.AddObject(new session()
                                            {
                                                accountId = account.Id,
                                                date = DateTime.UtcNow,
                                                hash = hash
                                            });
                 ctx.SaveChanges();
                 return hash;
             }, null);
 }
        public void DeleteSession(Account account)
        {
            EF.Execute("MySqlRepository.DeleteSession",
                ctx=>
                    {
                        var sessions = from s in ctx.sessions
                                       where s.accountId == account.Id
                                       select s;

                        foreach (var s in sessions)
                        {
                            ctx.DeleteObject(s);
                        }

                        ctx.SaveChanges();
                        return account;

                    }, null);
        }
 public void AddAccount(Account account)
 {
     EF.Execute("MySqlRepository.AddAccount",
         ctx =>
             {
                 ctx.accounts.AddObject(new account
                                            {
                                                name = account.Name,
                                                email = account.Email,
                                                category = account.Category,
                                                logo = account.Logo,
                                                password = Crypto.Encrypt<AesManaged>(
                                                     account.Password,
                                                     Setting.Value["cryptoPass"],
                                                     Setting.Value["cryptoSalt"]),
                                                status = "Active",
                                                created = DateTime.UtcNow
                                            });
                 ctx.SaveChanges();
                 return account;
             }, null);
 }
 public void Put(Account account)
 {
     _repository.UpdateAccount(account);
 }
        public void UpdateAccount(Account account)
        {
            EF.Execute("MySqlRepository.UpdateAccount",
                ctx =>
                    {
                        var found = ctx.accounts.First(a => a.id == account.Id);
                        {
                            found.name = account.Name;
                            found.email = account.Email;
                            found.category = account.Category;

                            if( ! string.IsNullOrEmpty(account.Logo) && found.logo != account.Logo)
                            found.logo = account.Logo;

                            if(! string.IsNullOrEmpty(account.Password) &&  found.password != account.Password)
                                found.password = Crypto.Encrypt<AesManaged>(
                                    account.Password,
                                    Setting.Value["cryptoPass"],
                                    Setting.Value["cryptoSalt"]);
                        }

                        ctx.SaveChanges();
                        return account;

                    }, null);
        }