public IActionResult GetToken([FromBody] Api_ProviderRequest user_provider) { var respond = _BLAPIProvider.getListProvider(user_provider); if (respond.status == "success") { respond.data = _tokenService.GenToken(respond); return(StatusCode(200, respond)); } else { return(StatusCode(401, respond)); } }
public RespondModel getListProvider(Api_ProviderRequest user_provider) { RespondModel modelRespond = new RespondModel(); try { if (string.IsNullOrEmpty(user_provider.username)) { modelRespond.status = "validate"; modelRespond.message = "request username"; return(modelRespond); } if (string.IsNullOrEmpty(user_provider.password)) { modelRespond.status = "validate"; modelRespond.message = "request password"; return(modelRespond); } if (string.IsNullOrEmpty(user_provider.type)) { modelRespond.status = "validate"; modelRespond.message = "request type"; return(modelRespond); } var model = _context.Api_Provider.Where(x => x.username == user_provider.username && x.password == user_provider.password && x.type == "pandasoft"); if (model.Count() > 0) { modelRespond.status = "success"; modelRespond.data = JsonConvert.SerializeObject(model.FirstOrDefault()); } else { modelRespond.status = "notfound"; modelRespond.message = "not found data"; } return(modelRespond); } catch (Exception ex) { modelRespond.status = "errortrycatch"; modelRespond.message = ex.ToString(); } return(modelRespond); }