public async Task <IActionResult> All() { var viewModel = new AchievementsViewModel() { AchievementsInGroups = await GetAllAchievementsInGroups() }; return(View(viewModel)); }
// GET: Achievements public IActionResult Index(int?currentYear, int page = 1, SortState sortOrder = SortState.IndicatorCodeAsc, string cmd = "") { int pageSize = 10; // количество элементов на странице int currYear = currentYear ?? DateTime.Now.Year; IEnumerable <Achievement> achievements = _context.Achievements .Include(a => a.Indicator) .Include(a => a.Univercity) .Where(t => t.Year == currYear) .OrderBy(s => s.Indicator.IndicatorCode); //Вычисление занятых мест if (cmd == "CalculatePositions") { achievements = Positions.Get(achievements.ToList()); _context.UpdateRange(achievements); _context.SaveChanges(); } // сортировка switch (sortOrder) { case SortState.IndicatorCodeDesc: achievements = achievements.OrderByDescending(s => s.Indicator.IndicatorCode); break; case SortState.UniversityNameAsc: achievements = achievements.OrderBy(s => s.Univercity.UniversityName); break; case SortState.UniversityNameDesc: achievements = achievements.OrderByDescending(s => s.Univercity.UniversityName); break; default: achievements = achievements.OrderBy(s => s.Indicator.IndicatorCode); break; } int count = achievements.Count(); List <int> years = _context.Indicators .OrderByDescending(f => f.Year) .Select(f => f.Year) .ToList(); years.Insert(0, currYear); years.Insert(0, currYear + 1); PageViewModel pageViewModel = new PageViewModel(count, page, pageSize); AchievementsViewModel achievementsViewModel = new AchievementsViewModel { PageViewModel = pageViewModel, SortViewModel = new SortViewModel(sortOrder), Achievements = achievements.Skip((page - 1) * pageSize).Take(pageSize).ToList(), ListYears = new SelectList(years.Distinct(), currYear) }; return(View(achievementsViewModel)); }
public ActionResult db_Create([DataSourceRequest] DataSourceRequest request, AchievementsViewModel db) { if (db != null && ModelState.IsValid) { AchievementService.Create(db); } return(Json(new[] { db }.ToDataSourceResult(request, ModelState))); }
public IActionResult AddAchievement() { var viewModel = new AchievementsViewModel { Players = _context.PlayerModel.ToList(), Achievements = _context.AchievementModel.ToList() }; return(View("AttachAchievement", viewModel)); }
public IActionResult Achievements() { if (_user == null) { _user = _userManager.GetUserAsync(User).Result; } var viewModel = new AchievementsViewModel(_db, _userManager, _user); return(View(viewModel)); }
public AccountInfoViewModel( IWargamingService wargamingService, IApplicationMessagesDispatcher applicationMessagesDispatcher) { _wargamingService = wargamingService; _applicationMessagesDispatcher = applicationMessagesDispatcher; AccountInfoViewState = AccountInfoViewState.Initial; AccountPropertiesViewModel = new AccountPropertiesViewModel(); AccountTanksViewModel = new AccountTanksViewModel(); AchievementsViewModel = new AchievementsViewModel(); }
public async Task <IActionResult> Achievements(AchievementsViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } // Achievements must be loaded explicitly due to lazy loading. Would optimize in production app _appDbContext.Entry(user).Collection(x => x.Achivements).Load(); for (int i = 0; i < model.AchievementWrapperList.Count; i++) { // Find matching achievement. Don't use foreach here since it gets messed up by the .Where() below AchievementWrapper aw = model.AchievementWrapperList[i]; UserAchievement targetAchievement = user.Achivements.Where(x => x.GlobalAchievementID == aw.Achievement.GlobalAchievementID).SingleOrDefault(); // Only update if there's a change if (targetAchievement == null && aw.IsAchieved == true) { UserAchievement toAdd = new UserAchievement { GlobalAchievementID = aw.Achievement.GlobalAchievementID, AchievedTime = DateTime.Now, ApplicationUserID = user.Id }; user.Achivements.Add(toAdd); } else if (targetAchievement != null && aw.IsAchieved == false) { user.Achivements.Remove(targetAchievement); } } var setResult = await _userManager.UpdateAsync(user); if (!setResult.Succeeded) { throw new ApplicationException($"Unexpected error occurred setting achievements for user with ID '{user.Id}'."); } StatusMessage = "Your settings have been updated"; return(RedirectToAction(nameof(Achievements))); }
public async Task <IActionResult> Achievements() { ViewData["Message"] = "Your achievements."; var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } // Achievements must be loaded explicitly due to lazy loading. Would optimize in production app _appDbContext.Entry(user).Collection(x => x.Achivements).Load(); var model = new AchievementsViewModel { AchievementWrapperList = new List <AchievementWrapper>(), CurrentUser = user, StatusMessage = StatusMessage }; foreach (GlobalAchievement a in _appDbContext.GlobalAchievements) { AchievementWrapper newW = new AchievementWrapper { Achievement = a }; // Find matching achievement try { UserAchievement targetAchievement = model.CurrentUser.Achivements.First(x => x.GlobalAchievementID == a.GlobalAchievementID); // Where(x => x.GlobalAchievementID == a.GlobalAchievementID).SingleOrDefault(); if (targetAchievement != null) { newW.IsAchieved = true; } else { newW.IsAchieved = false; } } catch { } model.AchievementWrapperList.Add(newW); } model.AchievementWrapperList = model.AchievementWrapperList.OrderByDescending(x => x.IsAchieved).ToList(); return(View(model)); }
// GET: Achievements public IActionResult Index(int?currentYear, int page = 1, SortState sortOrder = SortState.IndicatorCodeAsc) { int pageSize = 10; // количество элементов на странице int currYear = currentYear ?? DateTime.Now.Year; int univercityId = GetUniversiryId(); if (univercityId == 0) { string message = "Текущий пользователь не привязан к университету"; return(View("Message", message)); } var achievements = _context.Achievements .Include(a => a.Indicator) .Include(a => a.Univercity) .Where(t => (t.Year == currYear) & (t.UnivercityId == univercityId)) .OrderBy(s => s.Indicator.IndicatorCode); // сортировка switch (sortOrder) { case SortState.IndicatorCodeDesc: achievements = achievements.OrderByDescending(s => s.Indicator.IndicatorCode); break; default: achievements = achievements.OrderBy(s => s.Indicator.IndicatorCode); break; } int count = achievements.Count(); List <int> years = _context.Indicators .OrderByDescending(f => f.Year) .Select(f => f.Year) .ToList(); years.Insert(0, currYear); years.Insert(0, currYear + 1); PageViewModel pageViewModel = new PageViewModel(count, page, pageSize); AchievementsViewModel achievementsViewModel = new AchievementsViewModel { PageViewModel = pageViewModel, SortViewModel = new SortViewModel(sortOrder), Achievements = achievements.Skip((page - 1) * pageSize).Take(pageSize).ToList(), ListYears = new SelectList(years.Distinct(), currYear) }; return(View(achievementsViewModel)); }
public MainWindowViewModel() { // IFactory factory = new Factory(); // IActionQueue actionQueue = new BlockingActionQueue(); // IAchievementManager manager = null; if (!IsInDesignMode) { // manager = factory.CreateAchievementManager(); manager.FindAllAchievements(); Settings.Default.Achievements = Settings.Default.Achievements ?? new AchievementsSettings(); Settings.Default.Achievements.Load(manager.Achievements); } // Create sub view models WinListViewModel = new WinListViewModel(); StatisticsViewModel = new StatisticsViewModel(); OptionsViewModel = new OptionsViewModel(); PartyLineViewModel = new PartyLineViewModel(); ConnectionViewModel = new ConnectionViewModel(); PlayFieldPlayerViewModel = new PlayFieldViewModel(); PlayFieldSpectatorViewModel = new PlayFieldSpectatorViewModel(); AchievementsViewModel = new AchievementsViewModel(); PlayFieldViewModel = PlayFieldPlayerViewModel; // by default, player view // ConnectionViewModel.LoginViewModel.OnConnect += OnConnect; // ClientChanged += OnClientChanged; if (!IsInDesignMode) { // Create client Client = new Client.Client(factory, actionQueue, manager); } }
public AchievementsPage() { BindingContext = new AchievementsViewModel(this); InitializeComponent(); }
public ActionResult db_Destroy([DataSourceRequest] DataSourceRequest request, AchievementsViewModel db) { if (db != null) { AchievementService.Destroy(db); } return(Json(new[] { db }.ToDataSourceResult(request, ModelState))); }