public static Schedule Convert(this DbSchedule schedule) { return(new Schedule() { Id = schedule.ScheduleId, Number = schedule.Number ?? -1, Date = schedule.Date ?? DateTime.Now }); }
public int AddSchedule(int number, DateTime date) { var item = Context.Schedules.FirstOrDefault(x => x.Number == number && x.Date == date); if (item != null) { return(item.ScheduleId); } item = new DbSchedule() { Number = number, Date = date }; Context.Schedules.Add(item); try { Context.SaveChanges(); } catch (Exception ex) { Debug.WriteLine($"Exception:{ex.Message}"); return(-1); } return(item.ScheduleId); }