Exemplo n.º 1
0
        public User Create(string login, string password, string nickname, int homeId)
        {
            try
            {
                if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(nickname))
                {
                    throw new ArgumentException("Invalid parameters");
                }

                Home home = HomeRepository.Get(homeId);

                if (home == null)
                {
                    throw new ApplicationException("Home not found");
                }

                User user = new User
                {
                    Login    = login,
                    Nickname = nickname,
                    Password = Criptography.GetSHA1(password),
                    Home     = home
                };

                UserRepository.Save(user);

                return(user);
            }
            catch (ArgumentException ex)
            {
                Logger.LogWarning("Error while saving user to database", ex);
                throw;
            }
            catch (ApplicationException ex)
            {
                Logger.LogWarning("Error while saving user to database", ex);
                throw;
            }
            catch (Exception ex)
            {
                Logger.LogError("Unknown error while saving user to database", ex);
                throw new Exception("Unknown error while saving user to database");
            }
        }
Exemplo n.º 2
0
 public HomeDTO Get(int id)
 {
     return(Mapper.Map <Home, HomeDTO>(_homeRepository.Get(id)));
 }