Example #1
0
        public async Task <HttpResponseMessage> Put()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            var credentials = JsonConvert.DeserializeObject <FrontendUser>(jsonContent);

            if (_mInputValidator.UsernameTaken(credentials.username))
            {
                return(JsonResponse.JsonHttpResponse <object>(
                           ConfigurationManager.AppSettings["usernameError"]));
            }

            if (_mInputValidator.EmailTaken(credentials.email))
            {
                return(JsonResponse.JsonHttpResponse <object>(
                           ConfigurationManager.AppSettings["emailError"]));
            }

            var user = new User
            {
                Nickname = credentials.username, Password = credentials.password, Email = credentials.email,
                Name     = credentials.firstName, Surname = credentials.lastName
            };
            var result = await _mUserRepository.Add(user);

            return(JsonResponse.JsonHttpResponse <object>(true));
        }
        //GET: api/User
        //public bool Get()
        //{
        //return _mUserPresenter.GetUserList();
        //}

        //// GET: api/User/5
        //public IHttpActionResult Get(string username)
        //{
        //    var foundUser = _mUserRepository.GetList().FirstOrDefault(user => user.Nickname == username);
        //    if (foundUser == null)
        //    {
        //        return NotFound();
        //    }
        //    return Ok(foundUser);
        //}

        // POST: api/User
        //public void Post([FromBody]string value)
        //{
        //}

        //PUT: api/UserRegistration/5
        public async Task <HttpResponseMessage> Put()
        {
            HttpContent requestContent = Request.Content;
            string      jsonContent    = await requestContent.ReadAsStringAsync();

            var credentials = JsonConvert.DeserializeObject <User>(jsonContent);

            if (_mInputValidator.UsernameTaken(credentials.Nickname))
            {
                return(JsonResponse.JsonHttpResponse <Object>(StaticStrings.noUser));
            }
            else if (_mInputValidator.EmailTaken(credentials.Email))
            {
                return(JsonResponse.JsonHttpResponse <Object>(StaticStrings.EmailErr));
            }
            else
            {
                _mUserRepository.Add(credentials);
                return(JsonResponse.JsonHttpResponse <Object>(true));
            }

            //if (!_mInputValidator.UsernameTaken(credentials.Nickname)
            //    || !_mInputValidator.EmailTaken(credentials.Email))
            //{
            //    _mUserRepository.Add(credentials);
            //    return JsonResponse.JsonHttpResponse<Object>(true);
            //}
            //else
            //{
            //    return JsonResponse.JsonHttpResponse<Object>(false);
            //}
        }