public async Task <IActionResult> Edit(int id, [Bind("Id,ReportStatusId,Month,FromDate,ToDate,WeeklyTimeReportId,WeeklyTimeReportId1,WeeklyTimeReportId2,WeeklyTimeReportId3,WeeklyTimeReportId4,TotalTimeWorked")] MonthlyTimeReport monthlyTimeReport)
        {
            if (id != monthlyTimeReport.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    // Sum of all worked hours during the Month !
                    var applicationDbContext = _context.MonthlyTimeReport
                                               .Include(m => m.ReportStatus)
                                               .Include(m => m.WTR1)
                                               .Include(m => m.WTR1.Emloyee)
                                               .Include(m => m.WTR2)
                                               .Include(m => m.WTR2.Emloyee)
                                               .Include(m => m.WTR3)
                                               .Include(m => m.WTR3.Emloyee)
                                               .Include(m => m.WTR4)
                                               .Include(m => m.WTR4.Emloyee)
                                               .Include(m => m.WTR5)
                                               .Include(m => m.WTR5.Emloyee);
                    //monthlyTimeReport.TotalTimeWorked =
                    //      monthlyTimeReport.WTR1.WorkedHoursTotal
                    //    + monthlyTimeReport.WTR2.WorkedHoursTotal
                    //    + monthlyTimeReport.WTR3.WorkedHoursTotal
                    //    + monthlyTimeReport.WTR4.WorkedHoursTotal
                    //    + monthlyTimeReport.WTR5.WorkedHoursTotal;

                    _context.Update(monthlyTimeReport);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MonthlyTimeReportExists(monthlyTimeReport.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(ListMonthlyTimeReports)));
            }
            ViewData["ReportStatusId"]      = new SelectList(_context.ReportStatus, "ReportStatusName", "Id", monthlyTimeReport.ReportStatusId);
            ViewData["WeeklyTimeReportId"]  = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId);
            ViewData["WeeklyTimeReportId1"] = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId1);
            ViewData["WeeklyTimeReportId2"] = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId2);
            ViewData["WeeklyTimeReportId3"] = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId3);
            ViewData["WeeklyTimeReportId4"] = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId4);
            return(View(monthlyTimeReport));
        }
        public async Task <IActionResult> Create([Bind("Id,ReportStatusId,Month,FromDate,ToDate,WeeklyTimeReportId,WeeklyTimeReportId1,WeeklyTimeReportId2,WeeklyTimeReportId3,WeeklyTimeReportId4,TotalTimeWorked")] MonthlyTimeReport monthlyTimeReport)
        {
            if (ModelState.IsValid)
            {
                // Sum of all worked hours during the Month !
                var applicationDbContext = _context.MonthlyTimeReport
                                           .Include(m => m.ReportStatus)
                                           .Include(m => m.WTR1)
                                           .Include(m => m.WTR1.Emloyee)
                                           .Include(m => m.WTR1.WorkedHoursTotal)
                                           .Include(m => m.WTR2)
                                           .Include(m => m.WTR2.Emloyee)
                                           .Include(m => m.WTR2.WorkedHoursTotal)
                                           .Include(m => m.WTR3)
                                           .Include(m => m.WTR3.Emloyee)
                                           .Include(m => m.WTR3.WorkedHoursTotal)
                                           .Include(m => m.WTR4)
                                           .Include(m => m.WTR4.Emloyee)
                                           .Include(m => m.WTR4.WorkedHoursTotal)
                                           .Include(m => m.WTR5)
                                           .Include(m => m.WTR5.Emloyee)
                                           .Include(m => m.WTR5.WorkedHoursTotal);
                //monthlyTimeReport.TotalTimeWorked =
                //      monthlyTimeReport.WTR1.WorkedHoursTotal
                //    + monthlyTimeReport.WTR2.WorkedHoursTotal
                //    + monthlyTimeReport.WTR3.WorkedHoursTotal
                //    + monthlyTimeReport.WTR4.WorkedHoursTotal
                //    + monthlyTimeReport.WTR5.WorkedHoursTotal;

                _context.Add(monthlyTimeReport);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(ListMonthlyTimeReports)));
            }
            ViewData["ReportStatusId"]      = new SelectList(_context.ReportStatus, "ReportStatusName", "Id", monthlyTimeReport.ReportStatusId);
            ViewData["WeeklyTimeReportId"]  = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId);
            ViewData["WeeklyTimeReportId1"] = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId1);
            ViewData["WeeklyTimeReportId2"] = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId2);
            ViewData["WeeklyTimeReportId3"] = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId3);
            ViewData["WeeklyTimeReportId4"] = new SelectList(_context.WeeklyTimeReport, "Id", "WTRName", monthlyTimeReport.WeeklyTimeReportId4);
            return(View(monthlyTimeReport));
        }
        public IActionResult Index(MonthlyTimeReport montlyTimeReport)
        {
            // Sum of all worked hours during the Month !
            var applicationDbContext = _context.MonthlyTimeReport
                                       .Include(m => m.ReportStatus)
                                       .Include(m => m.WTR1)
                                       .Include(m => m.WTR1.Emloyee)
                                       .Include(m => m.WTR2)
                                       .Include(m => m.WTR2.Emloyee)
                                       .Include(m => m.WTR3)
                                       .Include(m => m.WTR3.Emloyee)
                                       .Include(m => m.WTR4)
                                       .Include(m => m.WTR4.Emloyee)
                                       .Include(m => m.WTR5)
                                       .Include(m => m.WTR5.Emloyee);

            //montlyTimeReport.TotalTimeWorked =
            //      montlyTimeReport.WTR1.WorkedHoursTotal
            //    + montlyTimeReport.WTR2.WorkedHoursTotal
            //    + montlyTimeReport.WTR3.WorkedHoursTotal
            //    + montlyTimeReport.WTR4.WorkedHoursTotal
            //    + montlyTimeReport.WTR5.WorkedHoursTotal;
            return(View(montlyTimeReport));
        }