예제 #1
0
        public uint CreateUser([FromBody] UserDetailStruct newUser)
        {
            if (newUser.firstName.Length < 1 || newUser.lastName.Length < 1)
            {
                // User's name cannot be empty
                var response = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content      = new StringContent("User could not be created"),
                    ReasonPhrase = "User cannot have an empty first or last name"
                };
                throw new HttpResponseException(response);
            }
            UserDetailStruct result = new UserDetailStruct();

            result.userID = access.CreateUser();
            access.SelectUser(result.userID);
            access.SetUserName(newUser.firstName, newUser.lastName);

            return(result.userID);
        }
예제 #2
0
        public UserDetailStruct GetUserDetail(uint userID)
        {
            UserDetailStruct result = new UserDetailStruct();

            access.SelectUser(userID);
            result.userID = userID;
            try
            {
                access.GetUserName(out result.firstName, out result.lastName);
            }
            catch (Exception)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("User details could not be retreived"),
                    ReasonPhrase = "User could not be found"
                };
                throw new HttpResponseException(response);
            }
            return(result);
        }