private static bool IsCorrectDate(DateTime now, RoutineDate routineDate) { return(now.DayOfWeek switch { DayOfWeek.Sunday => routineDate.Sun, DayOfWeek.Monday => routineDate.Mon, DayOfWeek.Tuesday => routineDate.Tue, DayOfWeek.Wednesday => routineDate.Wed, DayOfWeek.Thursday => routineDate.Thu, DayOfWeek.Friday => routineDate.Fri, DayOfWeek.Saturday => routineDate.Sat, _ => throw new ArgumentOutOfRangeException() });
public int CreateRoutine(DtoNewRoutine routine, int userId) { var idTypeOfId = routine.RoutineType switch { "Morning" => 1, "Evening" => 2, _ => 3 }; var newNote = new Note(); newNote.Text = routine.Note; newNote.Date = routine.RoutineDate; var newRoutineDate = new RoutineDate(); newRoutineDate.Start = routine.RoutineDate; if (routine.RoutineEndDate == null) { newRoutineDate.End = routine.RoutineDate; } if (routine.RoutineEndDate != null) { newRoutineDate.End = routine.RoutineEndDate.Value; } if (routine.DayOfWeek != null) { newRoutineDate.Mon = routine.DayOfWeek["mon"]; newRoutineDate.Tue = routine.DayOfWeek["tue"]; newRoutineDate.Wed = routine.DayOfWeek["wed"]; newRoutineDate.Thu = routine.DayOfWeek["thu"]; newRoutineDate.Fri = routine.DayOfWeek["fri"]; newRoutineDate.Sat = routine.DayOfWeek["sat"]; newRoutineDate.Sun = routine.DayOfWeek["sun"]; } else { newRoutineDate = null; } var waterIndicator = new Indicator(); waterIndicator.Date = routine.RoutineDate; waterIndicator.Value = routine.Water; waterIndicator.IndicatorTypeId = 1; var stressIndicator = new Indicator(); stressIndicator.Date = routine.RoutineDate; stressIndicator.Value = routine.Stress switch { "bad" => 3, "normal" => 2, _ => 1 }; stressIndicator.IndicatorTypeId = 2; var sleepingIndicator = new Indicator(); sleepingIndicator.Date = routine.RoutineDate; var x = routine.WakeUp - routine.GoToSleep; var sleeping = x?.TotalHours; if (sleeping != null) { sleepingIndicator.Value = (float)(sleeping); } sleepingIndicator.IndicatorTypeId = 3; var newRoutine = new Routine(); newRoutine.TypeOfRoutineId = idTypeOfId; newRoutine.Notes = new List <Note>(); newRoutine.Notes.Add(newNote); newRoutine.UserId = userId; newRoutine.RoutineDate = newRoutineDate; newRoutine.Indicators = new List <Indicator>(); newRoutine.Indicators.Add(waterIndicator); newRoutine.Indicators.Add(stressIndicator); newRoutine.Indicators.Add(sleepingIndicator); _context.Routines.Add(newRoutine); _context.SaveChanges(); AddProduct(routine.Cleanser, 1, newRoutine.Id); AddProduct(routine.Treatment, 2, newRoutine.Id); AddProduct(routine.Moisturizer, 3, newRoutine.Id); AddProduct(routine.SunScreen, 4, newRoutine.Id); AddProduct(routine.Other, 5, newRoutine.Id); return(newRoutine.Id); }