public IHttpActionResult Post(User user)
 {
     try
     {
         var repo = new ApplicationRepository();
         if (repo.IsUserExist(user))
         {
             return(Ok(new
             {
                 Message = Constants.MESSAGE_EXIST
             }));
         }
         else
         {
             repo.AddUser(user);
             return(Ok(new
             {
                 Message = Constants.MESSAGE_SUCCESS,
                 User = user
             }));
         }
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Beispiel #2
0
        public static void RegisterUser(string username, string password)
        {
            var validator           = new CredentialsValidator();
            var validationException = validator.Validate(new ValidatedObject(username, password));

            if (validationException != null)
            {
                throw new Exception($"Your {validationException.NotValidField} is not valid, " +
                                    $"Exception: {validationException.Message}");
            }
            ApplicationRepository.AddUser(username, password);
        }