public override int insert(object obj) { try { UserShiftEntity newUserShift = obj as UserShiftEntity; ShiftRegistration shift = newUserShift.Cast <ShiftRegistration>(); using (StoreManagementEntities context = new StoreManagementEntities()) { context.ShiftRegistrations.Add(shift); ShiftTime regShift = context.ShiftTimes.Find(shift.WeekDay, shift.Shift); regShift.Status = 0; context.SaveChanges(); } return(shift.Week); } catch (Exception e) { CustomException ex = new CustomException(GetType().Name + " : Insert " + obj.ToString() + "\n" + e.Message); ex.showPopupError(); } return(-1); }
public override void delete(object obj) { try { UserShiftEntity entity = obj as UserShiftEntity; using (StoreManagementEntities context = new StoreManagementEntities()) { ShiftRegistration delete = (from u in context.ShiftRegistrations where entity.Week == u.Week && entity.Shift == u.Shift && entity.WeekDay == u.WeekDay select u).Single(); context.ShiftRegistrations.Remove(delete); ShiftTime shift = context.ShiftTimes.Find(entity.WeekDay, entity.Shift); shift.Status = 1; context.SaveChanges(); } } catch (Exception e) { CustomException ex = new CustomException(GetType().Name + " : Delete " + obj.ToString() + "\n" + e.Message); ex.showPopupError(); } }