コード例 #1
0
        public HttpResponseMessage Register([FromBody] User user)
        {
            CustomResponse response;
            //Inserting the user into DB
            var result = _repository.Register(user);

            //If result is not null, it means that the given email is unique!
            if (result != null)
            {
                response = ResponseMessageHelper.CreateResponse(HttpStatusCode.Created, false, GenericMapper.MapToUserDTO(result), ConstantResponse.USER_CREATED);
                return(Request.CreateResponse <CustomResponse>(HttpStatusCode.Created, response));
            }

            //Email in use
            response = ResponseMessageHelper.CreateResponse(HttpStatusCode.BadRequest, true, null, ConstantResponse.EMAIL_IN_USE);
            return(Request.CreateResponse <CustomResponse>(HttpStatusCode.BadRequest, response));
        }