public HttpResponseMessage Post([FromBody] LoginViewModel ViewModel) { try { if (ViewModel == null) { return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Campos Inválidos", "text/plain")); } if (ModelState.IsValid) { var user = _UserRepo.GetByEmail(ViewModel.email); if (user == null) { return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Usuario Inexistente", "text/plain")); } else { if (Hashing.ValidatePassword(ViewModel.password, user.Password)) { Helper.AtualizarOrdens(user); AuthenticationModule authentication = new AuthenticationModule(); string token = authentication.CreateToken(user.Id, user.Email); //adiciona monitoramento das das ordems e saldos do usuario if (user.BinanceAPIKey != null && user.BinanceAPISecret != null && user.IsValidBinanceKeys) { WSMonitor monitor = WSMonitor.Instancia; monitor.AddMonitor(user); //monitor.RemoveDoubleConnection(user.Id); } return(Request.CreateResponse(HttpStatusCode.OK, token)); } else { return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Senha Inválida", "text/plain")); } } } var errorObj = ModelStateErrors.DisplayModelStateError(ModelState); return(Request.CreateResponse(HttpStatusCode.NotAcceptable, errorObj, "text/plain")); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }