public void UpdateCapstone(Capstone capstone)
        {
            List <Day> days = dayRepository.GetDaysByCapstoneId(capstone.CapstoneId);
            int        totB = 0;
            int        totW = 0;
            int        totS = 0;
            int        totF = 0;

            days.ForEach(d => {
                dayRepository.UpdateDay(d);
                totB += d.TotalMinutesBusy;
                totW += d.TotalMinutesWorked;
                totS += d.TotalMinutesSleep;
                totF += d.TotalMinutesFun;
            });
            capstone.TotalMinutesBusy   = totB;
            capstone.TotalMinutesFun    = totF;
            capstone.TotalMinutesSleep  = totS;
            capstone.TotalMinutesWorked = totW;

            int weeksHours = (days.Count / capstone.DaysPerWeek) * capstone.HoursPerWeek;

            capstone.OnTrack = (capstone.TotalMinutesWorked >= weeksHours) ? true : false;

            _context.Update(capstone);
            _context.SaveChanges();
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("LeagueId,LeagueName,Logo,HashPassword,LeagueKey")] Leagues leagues)
        {
            if (id != leagues.LeagueId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(leagues);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LeaguesExists(leagues.LeagueId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(leagues));
        }