private void Add(Time time) { using (var dao = new TimeRepository()) { dao.Add(time); } }
public async void AddOrUpdate(int index, int?id, DateTime fromDate, DateTime toDate, object _fromHour, object _toHour, bool status) { TimeSpan fromHour, toHour; string week = WeekCount(); _fromHour = _fromHour ?? new TimeSpan(); _toHour = _toHour ?? new TimeSpan(); if (_fromHour.GetType().Equals(typeof(DateTime))) { fromHour = ((DateTime)_fromHour).TimeOfDay; } else { fromHour = (TimeSpan)_fromHour; } if (_toHour.GetType().Equals(typeof(DateTime))) { toHour = ((DateTime)_toHour).TimeOfDay; } else { toHour = (TimeSpan)_toHour; } if (fromDate.TimeOfDay > toDate.TimeOfDay) { message = "Khoảng ngày không hợp lệ!"; return; } if (fromHour > toHour) { message = "Khoảng giờ không hợp lệ!"; return; } if (id != null) { TimeRule value = new TimeRule(id, fromDate, toDate, fromHour, toHour, week, status); ObservableCollection <TimeBased> timebased = new ObservableCollection <TimeBased>(books .Select(o => new TimeBased((int)id, o.ID))); value.TimeBased = timebased; bool result = await timeRepo.Update((int)id, value); if (result) { value.TimeBased = new ObservableCollection <TimeBased>(books.Select(o => new TimeBased((int)id, o))); timeRules[index] = value; message = MessageHelper.Get("up"); } else { message = MessageHelper.Get("upErr"); } } else { TimeRule value = new TimeRule(null, fromDate, toDate, fromHour, toHour, week, status); if (books.Count > 0) { ObservableCollection <TimeBased> timebased = new ObservableCollection <TimeBased>(books .Select(o => new TimeBased(0, o.ID))); value.TimeBased = timebased; } id = await timeRepo.Add(value); if (id > 0) { value.ID = (int)id; ObservableCollection <TimeBased> timebased = new ObservableCollection <TimeBased>(books .Select(o => new TimeBased((int)id, o))); value.TimeBased = timebased; timeRules.Add(value); message = MessageHelper.Get("add"); } else { message = MessageHelper.Get("addErr"); } } }