public IActionResult UpdateCategory(ClientCategoryModel inCategory) { ProfileModel profile = ValidationManager.ValidateUser(inCategory.Key); if (profile != null) { Category updatedProfile = ProfileManager.UpdateCategoryClient(inCategory, profile); return(Ok ( "Message: Profile with key " + inCategory.Key + " has been updated." + "\n" + "XScore = " + updatedProfile.XScore + ", YScore = " + updatedProfile.YScore )); } return(BadRequest("Invalid input to update category.")); }
/// <summary> /// Updates a category stat for a given profile /// </summary> /// <param name="inCategory">Object with the values to update the profile</param> /// <param name="updatedCategory">Category object with the updated values</param> /// <returns>Whether the update was successful</returns> public static Category UpdateCategoryClient(ClientCategoryModel inCategory, ProfileModel profile) { //Dictionaries from the inputted profile and the profile on the server Dictionary <string, Category> serverCategories = _profiles[profile.Username].CategoryScores; Category clientCategory = inCategory.ClientCategory; //Adds x and y values from the inputted profile if (serverCategories.ContainsKey(clientCategory.Name)) { serverCategories[clientCategory.Name].XScore += clientCategory.XScore; serverCategories[clientCategory.Name].YScore += clientCategory.YScore; } //Adds a new category if it did not already exist else { serverCategories.Add(clientCategory.Name, clientCategory); } UpdateRanks(clientCategory); SQLManager.UpdateCategory(profile.Username, serverCategories[clientCategory.Name]); return(serverCategories[clientCategory.Name]); }