public static async Task <string> CmdDeleteTodo(TSTodo ParTSTodo) { httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalData.CurrJWT); GlobalFunctions.CmdTrimEntity(ParTSTodo); //TSTodo tsTodoForSend = GlobalFunctions.CopyObject<TSTodo>(ParTSTodo); TSTodo tsTodoForSend = new TSTodo(); tsTodoForSend.UserID = ParTSTodo.UserID; tsTodoForSend.ID = ParTSTodo.ID; string result = await httpClient.SendJsonAsync <string>(HttpMethod.Delete, "todo/delete", tsTodoForSend); httpClient.DefaultRequestHeaders.Accept.Clear(); return(result); }
public static async Task <List <TSTodoEx> > CmdGetAllTodos() { try { httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalData.CurrJWT); List <TSTodoEx> result = await httpClient.MyGetJsonAsync <List <TSTodoEx> >("todo/getall"); foreach (var item in result) { GlobalFunctions.CmdAdjustDate(item, false); } return(result); } catch (Exception ex) { LocalFunctions.AddError(ex.Message, MethodBase.GetCurrentMethod(), true, false); return(new List <TSTodoEx>()); } }
internal static async Task <JwtResult> CmdDownloadToken(SecureString ParUserName, SecureString ParPassword, WebApiUserTypesEnum ParWebApiUserTypesEnum = WebApiUserTypesEnum.NotAuthorized) { try { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); string username = GlobalFunctions.ConvertToPlainString(ParUserName); if (string.IsNullOrEmpty(username)) { return(new JwtResult { ErrorMessage = "Username is not provided!" }); } string password = GlobalFunctions.ConvertToPlainString(ParPassword); if (string.IsNullOrEmpty(password)) { return(new JwtResult { ErrorMessage = "Password is not provided!" }); } var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("UserName", username + GlobalFunctions.GetRandomAlphaNumeric()), new KeyValuePair <string, string>("UserPass", password + GlobalFunctions.GetRandomAlphaNumeric()), new KeyValuePair <string, string>("UserType", ((int)ParWebApiUserTypesEnum).ToString() + GlobalFunctions.GetRandomAlphaNumeric()), new KeyValuePair <string, string>("MachineID", LocalData.MachineID + GlobalFunctions.GetRandomAlphaNumeric()), }); return(await httpClient.MyPostFormGetJsonAsync <JwtResult>("token", formContent)); } catch (Exception ex) { LocalFunctions.AddError(ex.Message, MethodBase.GetCurrentMethod(), true, false); return(new JwtResult()); } }
public async static void Authorize(string ParUserName, string ParPassword) { LocalData.CurrJWT = string.Empty; BlazorTimeAnalyzer.DevelopmentMode = !LocalData.ProductionOrDevelopmentMode; BlazorTimeAnalyzer.Reset(); BlazorTimeAnalyzer.LogAllAddition = true; BlazorTimeAnalyzer.Add("A1", MethodBase.GetCurrentMethod()); timerHelper.Stop(); if (await WebApi.CmdGetJWT(GlobalFunctions.ConvertToSecureString(ParUserName), GlobalFunctions.ConvertToSecureString(ParPassword), WebApiUserTypesEnum.Authorized)) { BlazorTimeAnalyzer.Add("A2", MethodBase.GetCurrentMethod()); TSUser tmpTSUser = new TSUser { UserName = ParUserName, Password = ParPassword, }; BlazorTimeAnalyzer.Add("A2", MethodBase.GetCurrentMethod()); LocalData.CurrTSUser = await WebApiFunctions.CmdTSUserAuthorize(tmpTSUser); BlazorTimeAnalyzer.Add("A3", MethodBase.GetCurrentMethod()); if (LocalData.CurrTSUser.UserName.ToLower().Equals("error!")) { LocalData.AppHasGlobalError = true; AddError(LocalData.CurrTSUser.FullName, MethodBase.GetCurrentMethod(), true, false); } else { LocalData.IsAuthenticated = !LocalData.CurrTSUser.ID.Equals(Guid.Empty); if (LocalData.IsAuthenticated) { timerHelper.OnTick = TimerTick; timerHelper.Start(1, 10000); BlazorTimeAnalyzer.Add("A4", MethodBase.GetCurrentMethod()); await WebApiFunctions.CmdGetFeedback(); BlazorTimeAnalyzer.Add("A5", MethodBase.GetCurrentMethod()); await WebApiFunctions.CmdGetReaction(); BlazorTimeAnalyzer.Add("A6", MethodBase.GetCurrentMethod()); LocalData.LoginLogout = LocalData.CurrTSUser.UserName; LocalData.btModal.Close(); CmdNavigate("DesktopPage"); LocalData.EventConsumerName = "TodosPage"; LocalData.componentBridge.InvokeRefresh(); LocalData.compHeader.Refresh(); LocalData.AppHasGlobalError = false; BlazorTimeAnalyzer.Add("A7", MethodBase.GetCurrentMethod()); } else { bool b = await WebApi.CmdGetJWT(LocalData.ServerNotAuthorizedUserName, LocalData.ServerNotAuthorizedUserPass, WebApiUserTypesEnum.NotAuthorized); if (b) { timerHelper.OnTick = TimerTick; timerHelper.Start(1, 10000); } LocalData.AppHasGlobalError = true; } } } BlazorTimeAnalyzer.LogAll(); }