Beispiel #1
0
        public HttpResponseMessage GetUser([FromBody] LoginView loginView)

        {
            List <string>   errorlist       = null;
            UserDetailsView userDetailsView = null;
            int             code            = (int)HttpStatusCode.OK;

            try
            {
                LoginValidator   validator           = new LoginValidator();
                ValidationResult results             = validator.Validate(loginView);
                bool             validationSucceeded = results.IsValid;
                if (validationSucceeded)
                {
                    Userservice userservice = new Userservice();
                    userDetailsView = userservice.GetUserWithDogs(loginView.UserEmail, loginView.UserPassword);
                    if (userDetailsView != null)
                    {
                        code = (int)HttpStatusCode.OK;
                    }
                    else
                    {
                        code = (int)HttpStatusCode.BadRequest;
                    }


                    //  return Ok();
                }
                else
                {
                    code = (int)HttpStatusCode.BadRequest;

                    errorlist = new List <string>();
                    foreach (var value in results.Errors)
                    {
                        errorlist.Add(value.ErrorCode);
                        //errorlist.Add(value.Errors);
                    }
                    //actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.BadRequest, errorlist);
                    //IList<ValidationFailure> failures = results.Errors;
                    //List<string> errorlist = new List<string>();
                    //foreach (ValidationFailure _error in failures)
                    //{
                    //    ModelState.AddModelError(_error.PropertyName, _error.ErrorMessage);
                    //    //foreach (var error in value.Errors)
                    //    //  errorlist.Add(value.ErrorMessage);
                    //    //errorlist.Add(value.Errors);
                    //}
                    //   return
                    //  return new System.Web.Http.Controllers.HttpActionContext()
                    //HttpActionContext actionContext = new HttpActionContext();


                    // ThrowResponseException(HttpStatusCode.NotAcceptable, errorlist);
                }
                if ((HttpStatusCode)code == HttpStatusCode.OK)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, userDetailsView));
                }
                else
                {// return Request.CreateResponse(HttpStatusCode.BadRequest, errorlist);
                    return(Request.CreateResponse(code));
                }
            }

            catch
            {
                bool x = ModelState.IsValid;
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }