Exemplo n.º 1
0
        private void ValidateRequest(UserRegisterRequest request)
        {
            if (request.AnyBlank())
            {
                throw new BadRequestException("Should register with correct information");
            }

            if (IsExistedEmail(request.Email))
            {
                throw new BadRequestException("This email has been used, please change!");
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage Register(UserRegisterRequest request)
        {
            ValidateRequest(request);

            var user = new User(request.Name, request.Email, request.Password, request.Gender);

            using (var tx = session.BeginTransaction())
            {
                session.Save(user);
                tx.Commit();
            }

            var userResult = new UserRegisterResult();

            userResult.AddLink("user/detail", string.Format("users/{0}", user.Id));
            return(Request.CreateResponse(HttpStatusCode.OK, userResult));
        }