private async Task <bool> StoreAsync(SurveyRating rating) { this.db.SurveyRatings.Add(rating); await this.db.SaveChangesAsync(); return(true); }
public async Task <SurveyRating> Post(Object model) { var jsonString = model.ToString(); List <Result> result = JsonConvert.DeserializeObject <List <Result> >(jsonString); SurveyRatingGenerator surveyRatingGenerator = new SurveyRatingGenerator(); SurveyRating surveyRating = surveyRatingGenerator.GetRating(result); await StoreAsync(surveyRating); return(surveyRating); }
public SurveyRating GetRating(List <Result> result) { _result = result; _resultDictionary = new Dictionary <string, int>(); SurveyRating surveyRating = new SurveyRating(); foreach (Result r in _result) { if (_resultDictionary.ContainsKey(r.Category)) { _resultDictionary[r.Category] = _resultDictionary[r.Category] + r.Rating; } else { _resultDictionary.Add(r.Category, r.Rating); } } foreach (string key in _resultDictionary.Keys) { switch (key) { case nameof(surveyRating.Admin): surveyRating.Admin = _resultDictionary[key]; break; case nameof(surveyRating.Business): surveyRating.Business = _resultDictionary[key]; break; case nameof(surveyRating.Architecture): surveyRating.Architecture = _resultDictionary[key]; break; case nameof(surveyRating.Development): surveyRating.Development = _resultDictionary[key]; break; case nameof(surveyRating.Security): surveyRating.Security = _resultDictionary[key]; break; case nameof(surveyRating.Documentation): surveyRating.Documentation = _resultDictionary[key]; break; case nameof(surveyRating.Compliance): surveyRating.Compliance = _resultDictionary[key]; break; case nameof(surveyRating.Processes): surveyRating.Processes = _resultDictionary[key]; break; default: // code block break; } } return(surveyRating); }