public async Task<CounterComment> SubmitCounterCommentAsync(String text, String name, Counter counter) { IsPending = true; ErrorMessage = null; // Create the new comment var comment = new CounterComment() { Score = 0, Text = text, User = name, ChampionFeedbackName = counter.ChampionFeedbackName, CounterId = counter.Id, Id = Guid.NewGuid().ToString(), CounterName = counter.Name }; try { counter.CounterComments.Add(comment); await counterCommentTable.InsertAsync(comment); return comment; } catch (MobileServiceInvalidOperationException ex) { ErrorMessage = ex.Message; return null; } catch (HttpRequestException ex2) { ErrorMessage = ex2.Message; return null; } finally { IsPending = false; } }
public async Task SubmitCounterRating(Counter counter, int score) { IsPending = true; ErrorMessage = null; // Check if the user already rated the counter var existingRating = counter.CounterRatings.Where(x => x.UniqueUser == GetDeviceId()).FirstOrDefault(); // If already rated, update to the new score if (existingRating != null){ // Case for pressing the opposite vote button -- change rating to it if (existingRating.Score != score){ existingRating.Score = score; } // Case for pressing the same vote button -- simply a score of 0 else{ existingRating.Score = 0; } // Update the rating in database try { await counterRatingTable.UpdateAsync(existingRating); } catch (Exception e) { ErrorMessage = e.Message; } } // Create a new rating otherwise else{ var newRating = new CounterRating(){ Score = score, UniqueUser = GetDeviceId(), Id = Guid.NewGuid().ToString(), CounterId = counter.Id, }; // Update the counter counter.CounterRatings.Add(newRating); // Insert rating into database try { await counterRatingTable.InsertAsync(newRating); } catch (Exception e) { ErrorMessage = e.Message; } } try{ var updatedCounter = await counterTable.LookupAsync(counter.Id); counter.Score = updatedCounter.Score; counter.CounterRatings = updatedCounter.CounterRatings; } catch (MobileServicePreconditionFailedException ex) { ErrorMessage = ex.Message; } // Server conflict catch (MobileServiceInvalidOperationException ex1) { ErrorMessage = ex1.Message; } catch (HttpRequestException ex2) { ErrorMessage = ex2.Message; } finally { IsPending = false; } }
public async Task<Counter> SubmitCounter(string champion, PageEnum.ClientChampionPage? page) { IsPending = true; ErrorMessage = null; //Convert the champion to a champion feedback var result = await champTable.Where(c => c.Name == champion).ToListAsync(); var submitChamp = result.FirstOrDefault(); // Create the new counter var counter = new Counter() { Score = 0, Id = Guid.NewGuid().ToString(), }; //Swap names around for easy matchup if (page == PageEnum.ClientChampionPage.EasyMatchup){ counter.ChampionFeedbackName = submitChamp.Name; counter.ChampionFeedbackId = submitChamp.Id; counter.Name = ChampionFeedback.Name; counter.Page = PageEnum.ChampionPage.Counter; this.ChampionFeedback.EasyMatchups.Add(counter); } //Handle the counter and synergy submissions normally else{ counter.ChampionFeedbackName = ChampionFeedback.Name; counter.ChampionFeedbackId = ChampionFeedback.Id; counter.Name = submitChamp.Name; if (page == PageEnum.ClientChampionPage.Counter) counter.Page = PageEnum.ChampionPage.Counter; else counter.Page = PageEnum.ChampionPage.Synergy; this.ChampionFeedback.Counters.Add(counter); } try { await counterTable.InsertAsync(counter); return counter; } catch (MobileServiceInvalidOperationException ex) { ErrorMessage = ex.Message; return null; } catch (HttpRequestException ex2) { ErrorMessage = ex2.Message; return null; } finally { IsPending = false; } }