public bool AddScheduleWeeks(int scheduleId, int loadId) { using (var db = new ScheduleKSTUContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { List <ScheduleWeeks> scheduleWeeks = db.RaschasovkaWeeks.Where(rw => rw.RaschasovkaId == loadId && rw.HoursForWeek != 0) .Select(rw => new ScheduleWeeks { ScheduleId = scheduleId, WeekId = rw.WeekId }).ToList(); db.ScheduleWeeks.AddRange(scheduleWeeks); db.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); throw; } } } return(true); }
public int AddScheduleTimeslot(Raschasovka load, TimeslotsCriteriaWeight timeslot) { using (var db = new ScheduleKSTUContext()) { Schedule schedule; using (var dbContextTransaction = db.Database.BeginTransaction()) { try { schedule = new Schedule { GroupId = load.GroupId, TeacherId = load.TeacherId, SubjectId = load.SubjectId, SubjectTypeId = load.SubjectTypeId, SemesterId = GetCurrentSemester().Id, HourId = timeslot.HourId, DayOfWeekId = timeslot.DayId, AuditoriumId = timeslot.AuditoriumId, }; db.Schedule.Add(schedule); db.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); throw ex; } } return(schedule.Id); } }
public bool InsertGenTimeslots(List <CriteriaRate> timeslots, int i) { using (var db = new ScheduleKSTUContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { ///////!!!!!!! db.Database.ExecuteSqlCommand("Delete From Gen_Timeslots"); try { foreach (CriteriaRate cr in timeslots) { db.GenTimeslots.Add(new GenTimeslots { AuditoriumId = cr.timeslots.AuditoriumId, DayId = cr.timeslots.DayId, HourId = cr.timeslots.HourId, Rate = cr.Rate + 1 }); } db.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); throw ex; } } } return(true); }
public bool InsertGenTeachers(List <RateData> teachers) { using (var db = new ScheduleKSTUContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { ///////!!!!!!! db.Database.ExecuteSqlCommand("Delete From Gen_Teachers"); try { foreach (RateData teach in teachers) { db.GenTeachers.Add(new GenTeachers { TeacherId = teach.Id, Rate = teach.Rate + 1 }); } db.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); throw ex; } } } return(true); }
public bool CriteriaEdit(Criteria criteria) { using (var db = new ScheduleKSTUContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { db.Update(criteria); db.SaveChanges(); } catch (Exception ex) { dbContextTransaction.Rollback(); throw ex; } } } return(true); }