예제 #1
0
        private string RegisterSession(Account account)
        {
            if(_repository.GetSession(account) != null)
                _repository.DeleteSession(account);

            return _repository.RegisterSession(account);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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);
 }
예제 #4
0
        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);
        }
예제 #5
0
 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);
 }
예제 #6
0
 public void Put(Account account)
 {
     _repository.UpdateAccount(account);
 }
예제 #7
0
        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);
        }