public object GetTies(int tieBreakGroup) { var results = new ResultCacher(Db).AllForThisElection; var persons = new PersonCacher(Db).AllForThisElection; var ties = results .Where(r => r.TieBreakGroup == tieBreakGroup) .Join(persons, r => r.PersonGuid, p => p.PersonGuid, (r, p) => new { r, p }) .Select(j => new { name = j.p.FullNameFL, isResolved = j.r.IsTieResolved.AsBoolean() }) .OrderBy(x => x.name); return(ties); }
public JsonResult SaveTieCounts(List <string> counts) { if (counts == null || counts.Count == 0) { return(new { Msg = "Nothing to Save" }.AsJsonResult()); } // input like: 2_3,5_3,235_0 var countItems = counts.Select(delegate(string s) { var parts = s.SplitWithString("_", StringSplitOptions.None); return(new { ResultId = parts[0].AsInt(), Value = parts[1].AsInt() }); }).ToList(); var resultsIds = countItems.Select(ci => ci.ResultId).ToArray(); var dbContext = GetNewDbContext(); var resultCacher = new ResultCacher(dbContext); var results = resultCacher.AllForThisElection.Where(r => resultsIds.Contains(r.Id)).ToList(); foreach (var result in results) { dbContext.Result.Attach(result); result.TieBreakCount = countItems.Single(ci => ci.ResultId == result.Id).Value; resultCacher.UpdateItemAndSaveCache(result); } dbContext.SaveChanges(); return(new { Saved = true }.AsJsonResult()); }