Пример #1
0
        public CreateUserResponse CreateUser(CreateUserRequest request)
        {
            CreateUserResponse response = new CreateUserResponse();

            try
            {
                User user = request.ConvertToUser();

                List <User> users = userRepository.ReadAll();

                if (users.Where(x => x.Username == user.Username).Count() > 0)
                {
                    throw new Exception("Korisnik sa datim korisničkim imenom već postoji u bazi!");
                }

                if (users.Where(x => x.Password == user.Password).Count() > 0)
                {
                    throw new Exception("Korisnik sa datim email-om već postoji u bazi!");
                }

                userRepository.Create(user);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Success = false;
            }
            return(response);
        }