public IActionResult Generate([FromHeader] string yearString, [FromHeader] string monthString) { try { var yearMonthPair = new YearMonthPair(yearString, monthString); repository.GeneratePlan(yearMonthPair.StartDate, yearMonthPair.EndDate); return(Ok(null)); } catch (Exception ex) { logger.LogError($"Failed to generate plan: {ex}"); return(BadRequest("Failed to generate plan!")); } }
public IActionResult Get([FromHeader] string yearString, [FromHeader] string monthString) { try { var yearMonthPair = new YearMonthPair(yearString, monthString); var planItems = repository.GetPlanItems(yearMonthPair.StartDate, yearMonthPair.EndDate).ToList(); var startDate = yearMonthPair.StartDate; var endDate = yearMonthPair.EndDate; var mappedResult = new List <PlanItemViewModel>(); while (startDate <= endDate) { var planItemViewModel = new PlanItemViewModel(startDate); foreach (var planItem in planItems.Where(p => p.Date == startDate && p.Engineer != null).ToList()) { planItemViewModel .SetEngineer( planItem.DayPart, planItem.EngineerId, planItem.Engineer.FirstName, planItem.Engineer.LastName); } mappedResult.Add(planItemViewModel); startDate = startDate.AddDays(1); } return(Ok(mappedResult)); } catch (Exception ex) { logger.LogError($"Failed to generate plan: {ex}"); return(BadRequest("Failed to generate plan!")); } }