public void AddMonth(ChooseDate date) { var findDate = context.Calendars.FirstOrDefault(d => d.SelectedDate == date.SelectedDate); if (findDate == null) { List <ChooseDate> dateRange = new List <ChooseDate>(); for (int i = 1; i <= DateTime.DaysInMonth(date.SelectedDate.Year, date.SelectedDate.Month); i++) { dateRange.Add(new ChooseDate() { IsSelected = false, SelectedDate = new DateTime(date.SelectedDate.Year, date.SelectedDate.Month, i) }); } context.Calendars.AddRange(dateRange); context.SaveChanges(); if (findDate != null) { context.Entry(findDate).State = EntityState.Detached; } } else { context.Entry(findDate).State = EntityState.Detached; } }
public ChooseDate CheckIn(ChooseDate date) { AddMonth(date); var dateAttach = context.Calendars.Attach(date); dateAttach.State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.SaveChanges(); return(date); }
public ChooseDate CheckIn(/*DateTime*/ ChooseDate date) { //_dataList.FirstOrDefault(d => DateTime.Compare(date, d.SelectedDate) == 0).IsSelected = true; //return _dataList.FirstOrDefault(d => DateTime.Compare(date, d.SelectedDate) == 0); throw new NotImplementedException(); }