/// <summary>Updates the collective asynchronous.</summary> /// <param name="name">The name.</param> /// <param name="description">The description.</param> /// <param name="size">The size.</param> /// <returns></returns> internal async Task <bool> UpdateCollectiveAsync(string name, string description, int size) { var currentUser = System.Text.Json.JsonSerializer.Deserialize <User>(ReadSetting("CurrentUser")); #pragma warning disable CA1305 // Specify IFormatProvider var collective = new Collective() { Id = Int32.Parse(ReadSetting("CurrentCollective")), OwnerId = currentUser.Id, Name = name, Description = description, Size = size }; #pragma warning restore CA1305 // Specify IFormatProvider Uri collectiveUri = new Uri("http://localhost:4000/Collectives/" + collective.Id); var collectiveJson = JsonConvert.SerializeObject(collective); #pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task Collective currentCollective = await CrudHandler.GetGenericEntityAsync <Collective>(collectiveUri, ReadSetting("AuthInfo")); #pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task var collectiveStringContent = new StringContent(collectiveJson, Encoding.UTF8, "application/json"); if (currentUser.Id == currentCollective.OwnerId) { await CrudHandler.PutGenericAsync(collectiveStringContent, ReadSetting("AuthInfo"), collectiveUri).ConfigureAwait(false); collectiveStringContent.Dispose(); return(true); } else { collectiveStringContent.Dispose(); await new MessageDialog("You are not allowed to edit this Collective, please pick one from the Manage Collectives Page", "Not allowed").ShowAsync(); return(false); } }
/// <summary>Updates the user asynchronous.</summary> /// <param name="firstname">The firstname.</param> /// <param name="lastname">The lastname.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <returns></returns> internal async Task <bool> UpdateUserAsync(string firstname, string lastname, string username, string password) { var currentUser = System.Text.Json.JsonSerializer.Deserialize <User>(ReadSetting("CurrentUser")); var user = new UserDto() { FirstName = firstname, LastName = lastname, Username = username, Password = password }; var userJson = JsonConvert.SerializeObject(user); var userStringContent = new StringContent(userJson, Encoding.UTF8, "application/json"); if (await CrudHandler.PutGenericAsync(userStringContent, ReadSetting("AuthInfo"), new Uri("http://localhost:4000/Users/" + currentUser.Id)).ConfigureAwait(false)) { userStringContent.Dispose(); string svcCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username + ":" + password)); SaveSetting("AuthInfo", svcCredentials); Uri UsersUri = new Uri("http://localhost:4000/Users/" + currentUser.Id); User x = await CrudHandler.GetGenericEntityAsync <User>(UsersUri, ReadSetting("AuthInfo")).ConfigureAwait(false); var CurrentUserJson = JsonConvert.SerializeObject(x); if (x.Username == username) { SaveSetting("CurrentUser", CurrentUserJson); } return(true); } else { userStringContent.Dispose(); } return(false); }