Пример #1
0
        public HttpResponseMessage post(EmailInsertRequest model)
        {
            if (!ModelState.IsValid)                                                    //if model request is invalid, it will return a bad request.
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (UserService.IsUser(model.Email))                                        //a function that checks if this person enters in their email is an actual user (actual email when signed up).
            {
                ApplicationUser currentUser = UserService.GetUser(model.Email);         //a function that gets the userId through email.

                Guid tokenId = TokenService.Post(currentUser.Id);                       //generate a unique token for the user pw reset request.

                ContactEmailService.AdminResetEmailPassword(model, tokenId);            //calling the function from the ContactEmailService class that includes the 'emailInsertRequest model'.

                ItemResponse <Guid> response = new ItemResponse <Guid>();               //Wrap up the 'Guid' in an envelope(which is the item response).
                response.Item = tokenId;                                                //'ItemReponse' gives structure to the json which gets passed back to the user.
                return(Request.CreateResponse(HttpStatusCode.OK, response));            //Return the tokenId to the user.
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No account exist"));
            }
        }