public string SaveAcceleratorsForTeam(TeamAppAcceleratorsDto teamAppAcceleratorsDto) { using (ConsoleRepository) { // Check does Team Accelerators exist var team = ConsoleRepository.Query<Team>(t => t.AppAccelerators).FirstOrDefault(t => t.Id == teamAppAcceleratorsDto.TeamId); bool appAcceleratorsChanged = false; if (team != null) { // Remove Accelerators that need to be removed var currentTeamAppAccelerators = team.AppAccelerators.Select(t => t.Id).ToList(); var appAcceleratorsToRemove = currentTeamAppAccelerators.Except(teamAppAcceleratorsDto.TeamAppAcceleratorsIdList ?? new List<string>()).ToList(); foreach (var appAcceleratorId in appAcceleratorsToRemove.Where(a => !String.IsNullOrEmpty(a))) { var aa = team.AppAccelerators.FirstOrDefault(a => a.Id == appAcceleratorId); team.AppAccelerators.Remove(aa); appAcceleratorsChanged = true; } // Add Accelerators that need to be added foreach ( var appAcceleratorId in teamAppAcceleratorsDto.TeamAppAcceleratorsIdList ?? new List<string>()) { if (team.AppAccelerators.Any(a => a.Id == appAcceleratorId)) continue; if (!String.IsNullOrEmpty(appAcceleratorId)) { var appAcceleratorToAdd = new AppAccelerator() { Id = appAcceleratorId }; ConsoleRepository.AttachUnchanged<AppAccelerator>(appAcceleratorToAdd); team.AppAccelerators.Add(appAcceleratorToAdd); appAcceleratorsChanged = true; } } ConsoleRepository.SaveChanges(); if (appAcceleratorsChanged) return "Saved Accelerator(s) for Team"; else return "Accelerator(s) for Team have not changed"; } else { return "Save Accelerators - Team does not Exist"; } } }
public ActionResult SaveAcceleratorsForTeam(TeamAppAcceleratorsDto teamAcceleratorsDto) { try { var result = _adminModuleManager.SaveAcceleratorsForTeam(teamAcceleratorsDto); return new JsonNetResult { Data = result }; } catch (Exception ex) // TODO: Remove { _logHandler.WriteLog(ex.ToString(), LogSeverity.Error, LogCategory.BusinessComponent); throw new HttpException(500, "Server Error"); } }