Ejemplo n.º 1
0
        public static User CreateUser(UserRegisterDto registerDto)
        {
            var newUser = new User()
            {
                UserName = registerDto.UserName.ToLower(),
                NickName = registerDto.NickName,
                AuthCode = registerDto.AuthCode
            };

            return(newUser);
        }
Ejemplo n.º 2
0
        public static User CreateUser(UserRegisterDto registerDto)
        {
            var newUser = new User()
            {
                UserName = registerDto.UserName.ToLower(),
                NickName = registerDto.NickName,
                AuthCode = registerDto.AuthCode
            };

            return newUser;
        }
Ejemplo n.º 3
0
        public HttpResponseMessage Register(UserRegisterDto registerDto)
        {
            var operationResult = this.PerformOperationAndHandleExceptions(() =>
            {
                if (ModelState.IsValid && registerDto != null)
                {
                    var existingUser = NationalPlacesDAL.Get<User>("UsersInformation")
                        .FirstOrDefault(x => x.UserName == registerDto.UserName.ToLower() ||
                                             x.NickName.ToLower() == registerDto.NickName.ToLower());
                    if (existingUser != null)
                    {
                        throw new InvalidOperationException("User name or nickname is already taken");
                    }

                    var newUser = UserRegisterDto.CreateUser(registerDto);
                    NationalPlacesDAL.Add(newUser, "UsersInformation");

                    newUser.SessionKey = this.GenerateSessionKey(newUser.Id.Value.Pid);
                    NationalPlacesDAL.SaveEntity(newUser, "UsersInformation");

                    var loginInforrmation = UserLoggedInDto.FromUser.Compile()(newUser);

                    var response = Request.CreateResponse(HttpStatusCode.Created, loginInforrmation);
                    return response;
                }
                else
                {
                    var errors = String.Join("\n ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
                    var errorMessage = string.Format("User input was not validated:\n {0}", errors);
                    throw new ArgumentException(errorMessage);
                }
            });

            return operationResult;
        }