public async Task <TokenModel> AuthorizeUser(LoginModel loginModel) { TokenModel tokenModel = new TokenModel(); try { dynamic dynamicJson = new ExpandoObject(); dynamicJson.Email = loginModel.Email; dynamicJson.Password = loginModel.Password; HttpResponseMessage httpRespon = await Client.PostAsAsync(LoginUrl, dynamicJson); var responJsonText = await httpRespon.Content.ReadAsStringAsync(); int statusCode = Convert.ToInt32(httpRespon.StatusCode); if (httpRespon == null) { tokenModel.message = ResponceCode.customErrorFunction(651, null);; } else if (httpRespon.IsSuccessStatusCode) { return(tokenModel = JsonConvert.DeserializeObject <TokenModel>(responJsonText)); } else { var message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText); tokenModel.message = ResponceCode.customErrorFunction(Convert.ToInt32(statusCode), (message == null ? null: message.message)); } } catch (Exception Ex) { Debug.Write(Ex.Message); tokenModel.message = ResponceCode.customErrorFunction(651, null); } return(tokenModel); }
public static async Task <CustomeMessage> UpdatePreferredRole(string role) { CustomeMessage message = new CustomeMessage(); try { dynamic dynamicJson = new ExpandoObject(); dynamicJson.RoleId = role; HttpResponseMessage httpRespon = await Client.PostAsAsync(UpdatePreferredRoleurl, dynamicJson); var responJsonText = await httpRespon.Content.ReadAsStringAsync(); int statusCode = Convert.ToInt32(httpRespon.StatusCode); if (Convert.ToInt32(statusCode) == 401) { message.message = Convert.ToString(statusCode); } else if (httpRespon.IsSuccessStatusCode) { return(message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText)); } else { message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText); message.message = ResponceCode.customErrorFunction(Convert.ToInt32(statusCode), message.message); } } catch (Exception Ex) { Debug.Write(Ex.Message); } return(message); }
public async Task <CustomeMessage> ActivateUser(UserActiveModel userActiveModel) { CustomeMessage message = new CustomeMessage(); try { dynamic dynamicJson = new ExpandoObject(); dynamicJson.OTPCode = userActiveModel.OtpCode; dynamicJson.Password = userActiveModel.Password; dynamicJson.Email = userActiveModel.EmailId; HttpResponseMessage httpRespon = await Client.PostAsAsync(ActivateUserurl, dynamicJson); var responJsonText = await httpRespon.Content.ReadAsStringAsync(); if (httpRespon.IsSuccessStatusCode) { return(message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText)); } else { message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText); message.message = ResponceCode.customErrorFunction(Convert.ToInt32(httpRespon.StatusCode), message.message); } } catch (Exception Ex) { Debug.Write(Ex.Message); } return(message); }
public static async Task <CustomeMessage> Logout() { CustomeMessage message = new CustomeMessage(); try { HttpResponseMessage httpRespon = await Client.PostAsAsync(LogoutUrl, null); var responJsonText = await httpRespon.Content.ReadAsStringAsync(); if (httpRespon.IsSuccessStatusCode) { return(message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText)); } else { message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText); message.message = ResponceCode.customErrorFunction(Convert.ToInt32(httpRespon.StatusCode), message.message); } } catch (Exception Ex) { Debug.Write(Ex.Message); } return(message); }
SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { HttpResponseMessage response = new HttpResponseMessage(); try { // Change the request-side here based on the HttpRequestMessage request.Headers.Clear(); request.Headers.Add("ZUMO-API-VERSION", "2.0.0"); request.Headers.Add("X-ZUMO-AUTH", Client.token); request.Headers.Add("X-ACCESS-ROLE", Client.roleId); var request1 = request.RequestUri.ToString().Replace("updatedAt", "UpdatedAt"); request.RequestUri = new Uri(request1); Debug.WriteLine(request1); Debug.WriteLine(Client.token); Debug.WriteLine(Client.roleId); // Do the request response = await base.SendAsync(request, cancellationToken); if (Convert.ToInt32(response.StatusCode) == 401) { Debug.WriteLine(ResponceCode.customErrorFunction(401, null)); Client.IsLogged = false; return(null); } else if (Convert.ToInt32(response.StatusCode) == 403) { Debug.WriteLine(ResponceCode.customErrorFunction(403, null)); Client.IsPermission = false; return(null); } return(response); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(response); }
public async Task <CustomeMessage> PostUser(UserModel userModel) { CustomeMessage message = new CustomeMessage(); try { dynamic dynamicJson = new ExpandoObject(); dynamicJson.FirstName = userModel.FirstName; dynamicJson.LastName = userModel.LastName; // dynamicJson.OrgId = userModel.OrgId; dynamicJson.EmployeeId = userModel.EmployeeId; dynamicJson.RoleId = userModel.RoleId; dynamicJson.EUSR = userModel.EUSR; dynamicJson.ContactNo = userModel.ContactNo; dynamicJson.Email = userModel.Email; // dynamicJson.Password = userModel.Password; HttpResponseMessage httpRespon = await Client.PostAsAsync(Signupurl, dynamicJson); var responJsonText = await httpRespon.Content.ReadAsStringAsync(); message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText); string statusCode = Convert.ToString(httpRespon.StatusCode); if (httpRespon.IsSuccessStatusCode) { return(message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText)); } else { //if (message.message == "USER_EXISTS_NOT_ACTIVATED") // return message; message.message = ResponceCode.customErrorFunction(Convert.ToInt32(httpRespon.StatusCode), message.message); } } catch (Exception Ex) { Debug.Write(Ex.Message); } return(message); }
public async Task <CustomeMessage> ChangePassword(ChangePasswordModel changePassword) { CustomeMessage message = new CustomeMessage(); try { Client client = new Client(); dynamic dynamicJson = new ExpandoObject(); dynamicJson.OldPassword = changePassword.OldPassword; dynamicJson.NewPassword = changePassword.NewPassword; HttpResponseMessage httpRespon = await Client.PostAsAsync(ChangePasswordUrl, dynamicJson); var responJsonText = await httpRespon.Content.ReadAsStringAsync(); int statusCode = Convert.ToInt32(httpRespon.StatusCode); if (Convert.ToInt32(httpRespon.StatusCode) == 401) { message.message = Convert.ToString(statusCode); } else if (httpRespon.IsSuccessStatusCode) { return(message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText)); } else { message = JsonConvert.DeserializeObject <CustomeMessage>(responJsonText); message.message = ResponceCode.customErrorFunction(Convert.ToInt32(statusCode), message.message); } } catch (Exception Ex) { Debug.Write(Ex.Message); } return(message); }