/// <summary> /// Gets the last schedule based on the past days /// </summary> /// <param name="daysPassed"></param> /// <returns></returns> public Schedule getLastSchedule(int daysPassed) { SqlConnection conn = new SqlConnection(con); conn.Open(); SqlCommand comm = new SqlCommand(null, conn); comm.CommandText = "SELECT * FROM Schedule s WHERE " + daysPassed + "=(SELECT COUNT(DISTINCT ScheduleDate) FROM Schedule sc WHERE s.ScheduleDate<=sc.ScheduleDate)"; Schedule sched = new Models.Schedule(); SqlDataReader read = comm.ExecuteReader(); if (read.HasRows) { while (read.Read()) { sched.Id = read.GetString(0); sched.ScheduleDate = read.GetDateTime(3); if (sched.UserRoles.ContainsKey(read.GetInt32(1))) { } else { sched.UserRoles.Add(read.GetInt32(1), read.GetInt32(2)); } } } else { Console.WriteLine("No rows found."); } read.Close(); return(sched); }
public static Tuple <string, bool> Insert(int eventId, int userId) { using (var db = new Models.ModelContext()) { var currEvent = db.Events.Where(e => e.Id.Equals(eventId)); var currUser = db.Users.Where(u => u.Id.Equals(userId)); // If any of the elements are not present in db if (!(currEvent.Any() && currUser.Any())) { return(new Tuple <string, bool>("Atleiskite, įvyko klaida", false)); } var schedule = db.Schedules.Where(s => (s.Event_id == eventId) && (s.User_id == userId)); if (schedule.Any()) { return(new Tuple <string, bool>("Šis renginys jau pridėtas į Jūsų tvarkaraštį", false)); } else { var newSchedule = new Models.Schedule(); newSchedule.Event_id = eventId; newSchedule.User_id = userId; db.Schedules.Add(newSchedule); db.SaveChanges(); return(new Tuple <string, bool>("Renginys sėkmingai pridėtas į Jūsų tvarkaraštį.", true)); } } }
/// <summary> /// Gets a schedule based on the date /// </summary> /// <param name="date"></param> /// <returns></returns> public Schedule getScheduleByDate(DateTime date) { SqlConnection connection = new SqlConnection(con); connection.Open(); SqlCommand command = new SqlCommand(null, connection); command.CommandText = "SELECT * FROM Schedule WHERE ScheduleDate = @scheduledate"; SqlParameter scheduleDateParam = new SqlParameter("@scheduledate", SqlDbType.DateTime, 255); scheduleDateParam.Value = date; command.Parameters.Add(scheduleDateParam); Schedule schedule = new Models.Schedule(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { schedule.Id = reader.GetString(0); schedule.ScheduleDate = reader.GetDateTime(3); schedule.UserRoles.Add(reader.GetInt32(1), reader.GetInt32(2)); } } else { Console.WriteLine("No rows found."); } reader.Close(); return(schedule); }
//execute save public ScheduleEdit SaveSchedule(ScheduleEdit model) { if (model != null && Guid.TryParse(model.JobId, out Guid jobid)) { using (var context = new CloudbassContext()) { var schedule = new Models.Schedule() { JobId = jobid, text = model.text?.Trim(), start_date = model.start_date, end_date = model.end_date, SchType = model.SchType }; context.Schedules.Add(schedule); context.SaveChanges(); return(model); } } // Return false if customeredit == null or CustomerID is not a guid return(null); }
private void CreateSchedule() { var schedule = new Models.Schedule { Description = _description, DayOfWeek = (int)this.day.Id }; Data.ScheduleDatabase.SaveItem(schedule); }
public void EditSchedule(Models.Schedule schedule) { var sch = RE.Schedules.Single(p => p.id == schedule.id); sch.name = schedule.name; sch.description = schedule.description; sch.type = schedule.type; sch.state = schedule.state; RE.SaveChanges(); }
public static int SaveItem(Models.Schedule item) { lock (locker) { if (item.Id != 0) { me.database.Update(item); return(item.Id); } else { return(me.database.Insert(item)); } } }
public void CreateSchedule(string schName, string schDescription, string schType) { var userId = (int)Session["UserId"]; var newSchedule = new Models.Schedule() { userId = userId, name=schName, description=schDescription, type=schType, state="ACTIVE" }; Sch.CreateSchedule(newSchedule); int newSchId = Sch.OneSchedule(schName, schDescription, userId); Session.Add("SchId", newSchId); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Schedule = await _context.Schedules .Include(s => s.Trainer).FirstOrDefaultAsync(m => m.Id == id); if (Schedule == null) { return(NotFound()); } return(Page()); }
public void ParseGroupSchedule(int id, Dictionary <WeekTypes, List <Lesson> > groupSchedule) { _dataContext.Schedules.RemoveRange(_dataContext.Schedules.Where(s => s.GroupId == id)); foreach (var(key, value) in groupSchedule) { foreach (var lesson in value) { var schedule = new Models.Schedule(); schedule.Day = lesson.Day; schedule.Name = lesson.Name; schedule.GroupId = id; schedule.IsEvenWeek = key == WeekTypes.Even; schedule.Order = lesson.Order; List <SubGroupLesson> subGroupLessons = null !; if (lesson.Subgroups == null) { schedule.Classroom = lesson.LectureHall; schedule.Teacher = lesson.Teacher; schedule.Type = lesson.Type; schedule.IsSubgroup = false; } else { schedule.IsSubgroup = true; subGroupLessons = lesson.Subgroups.Select(subgroup => new SubGroupLesson { Classroom = subgroup.LectureHall, Teacher = subgroup.Teacher, Name = subgroup.Name, Course = schedule }).ToList(); } _dataContext.Schedules.Add(schedule); if (subGroupLessons != null) { _dataContext.SubGroupLessons.AddRange(subGroupLessons); } } } _dataContext.SaveChanges(); }
public void CreateSchedule(string schName, string schDescription, string schType) { var userId = (int)Session["UserId"]; var newSchedule = new Models.Schedule() { userId = userId, name = schName, description = schDescription, type = schType, state = "ACTIVE" }; Sch.CreateSchedule(newSchedule); int newSchId = Sch.OneSchedule(schName, schDescription, userId); Session.Add("SchId", newSchId); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Schedule = await _context.Schedules.FindAsync(id); if (Schedule != null) { _context.Schedules.Remove(Schedule); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public ActionResult Schedule(Models.Schedule schedule) { if (ModelState.IsValid) { db.Schedules.Add(schedule); try { db.SaveChanges(); return(RedirectToAction("Schedule")); } catch (Exception ex) { ViewBag.Error = ex.Message; } } return(View()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Schedule = await _context.Schedules .Include(s => s.Trainer).FirstOrDefaultAsync(m => m.Id == id); if (Schedule == null) { return(NotFound()); } ViewData["TrainerId"] = new SelectList(_context.Trainers, "Id", "Name"); ViewData["Day"] = new SelectList(Constant.GetDaysOfWeek()); return(Page()); }
public ScheduleEdit SaveSchedule(ScheduleEdit model) { //if (model != null && string.IsNullOrEmpty(model.JobId) ) if (model != null && Guid.TryParse(model.Id.ToString(), out Guid jobid)) { using (var context = new CBDBEntities()) { //if (string.IsNullOrEmpty(jobedit.Id)) //{ var schedule = new Models.Schedule() { //Id = newGuid.ToString(), //Id = customerid, // JobId = model.JobId, JobId = jobid.ToString(), text = model.text, start_date = model.start_date, end_date = model.end_date, //statusId = model.SelectedStatus, SchTypeId = model.SelectedSchType }; schedule.SchType = context.SchTypes.Find(schedule.SchTypeId); //schedule.ScheduleStatu = context.ScheduleStatus.Find(schedule.statusId); context.Schedules.Add(schedule); context.SaveChanges(); var schTypesRepo = new SchTypeRepository(); model.SchType = schTypesRepo.GetSchTypes(); var schStatuRepo = new ScheduleStatuRepository(); //model.ScheduleStatu = schStatuRepo.GetScheduleStatus(); return(model); } } // Return false if customeredit == null or CustomerID is not a guid return(null); }
public static async Task <List <Models.Lesson> > RefreshCurrentLessons() { Models.Preferences.Token token = App.PreferenceDatabase.GetToken(); if (token == null || !token.IsLoggedIn) { throw new Exceptions.SessionTimeoutException(); } Models.Schedule schedule = await fetchCurrent(token.AccessToken); if (schedule != null) { App.CurrentInfoDatabase.ResetAsync(schedule.Lessons); return(schedule.Lessons); } else { return(null); } }
// POST: api/Schedule public JObject Post(Guid token, string faculty, string specialty, string section, int term, string monday_ch, string monday_z, string tuesday_ch, string tuesday_z, string wednesday_ch, string wednesday_z, string thursday_ch, string thursday_z, string friday_ch, string friday_z, string saturday_ch, string saturday_z, string sunday_ch, string sunday_z) { if (CurrentMemory.CurrentUsers.Find(x => x.Token == token).Token != Guid.Empty) { var res = db.Schedules.FirstOrDefault((x) => x.Faculty == faculty && x.Specialty == specialty && x.Section == section && x.Term == term); Models.Schedule tmp = new Models.Schedule { Id = res == null?Guid.NewGuid() : res.Id, Faculty = faculty, Specialty = specialty, Section = section, Term = term, Monday_Ch = monday_ch, Monday_Z = monday_z, Tuesday_Ch = tuesday_ch, Tuesday_Z = tuesday_z, Wednesday_Ch = wednesday_ch, Wednesday_Z = wednesday_z, Thursday_Ch = thursday_ch, Thursday_Z = thursday_z, Friday_Ch = friday_ch, Friday_Z = friday_z, Saturday_Ch = saturday_ch, Saturday_Z = saturday_z, Sunday_Ch = sunday_ch, Sunday_Z = sunday_z }; db.Schedules.Add(tmp); db.SaveChanges(); return(JObject.FromObject(new { status = "ok" })); } else { return(JObject.FromObject(new { status = "fail" })); } }
public IActionResult OnPost() { if (!ModelState.IsValid) { PopulateSelectLists(); return(Page()); } var trainer = _context.Trainers.FirstOrDefault(t => t.Id == AddScheduleForm.TrainerId); var schedule = new Models.Schedule { Day = AddScheduleForm.Day, ProgramName = trainer.Specialty, StartTime = AddScheduleForm.StartTime, EndTime = AddScheduleForm.EndTime, TrainerId = AddScheduleForm.TrainerId }; _context.Schedules.Add(schedule); _context.SaveChanges(); return(RedirectToPage("/Schedule/details", new { Id = schedule.Id })); }
public void ReParseSchedule(List <Schedule.Group> groups) { var batchSize = 10; var current = 0; foreach (var @group in groups.Distinct(new GroupsComparer())) { _dataContext.Groups.Add(new Group { Id = group.Id, Name = group.Name }); if (group.Lessons == null) { continue; } foreach (var week in group.Lessons) { foreach (var lesson in week.Value) { var schedule = new Models.Schedule(); schedule.Day = lesson.Day; schedule.Name = lesson.Name; schedule.GroupId = group.Id; schedule.IsEvenWeek = week.Key == WeekTypes.Even; schedule.Order = lesson.Order; List <SubGroupLesson> subGroupLessons = null !; if (lesson.Subgroups == null) { schedule.Classroom = lesson.LectureHall; schedule.Teacher = lesson.Teacher; schedule.Type = lesson.Type; schedule.IsSubgroup = false; } else { schedule.IsSubgroup = true; subGroupLessons = lesson.Subgroups.Select(subgroup => new SubGroupLesson { Classroom = subgroup.LectureHall, Teacher = subgroup.Teacher, Name = subgroup.Name, Course = schedule }).ToList(); } _dataContext.Schedules.Add(schedule); if (subGroupLessons != null) { _dataContext.SubGroupLessons.AddRange(subGroupLessons); } current++; if (current >= batchSize) { _dataContext.SaveChanges(); current = 0; } } } } }
public async Task <Models.Schedule> AddSchedule([FromBody] Models.Schedule schedule) { var result = await _scheduleUnitOfWork.Repository.Insert(schedule); return(await GetScheduleById(schedule.Id, new string[] { "Teacher", "Room", "Subject", "Lesson" })); }
//private static User[] users; //private static Urgency[] urgencies; //private static Importance[] importancies; //private static Interval[] intervals; //private static Criteria[] criterias; //private static Models.Schedule[] schedules; //private static TimeRule[] timeRules; //private static TimeBinding[] timeBindings; //private static Models.Task[] tasks; //private static Step[] steps; //private static Tree[] trees; //PLEASE DO NOT CALL THIS METHOD IT IS TOTALLY BAD. public static void Seed() { var user = User.CreateUser("xxxrassiyavperedxxx", "A.Pistoletov", new DateTime(1985, 3, 22), "secret_pass", DateTime.Now); //var user = (User)DAL.SqlRepository.Users.Find("xxxrassiyavperedxxx"); var tree = Tree.CreateTree(user, user.Login, "new era of trees", "must work please"); // var tree = Tree.FindTreesForUser(user).First(); var importancies = Importance.GetViableImportanceLevels(); var urgencies = Urgency.GetViableUrgencyLevels(); var criterias = new Criteria[] { Criteria.CreateCriteria(0, 10, "wtuk"), Criteria.CreateCriteria(0, 1, "raz"), Criteria.CreateCriteria(0, 666, "fragov v cs") }; //var criterias = DAL.SqlRepository.Criterias.Cast<Criteria>().ToList(); var tasks = new Task[4]; tasks[0] = Task.CreateTask(DateTime.Now, DateTime.Now.AddDays(5), urgencies[0].UrgencyName, importancies[0].ImportanceName, importancies[0], urgencies[0], criterias[0].Id, criterias[0], "task 1", tree.MainTask, tree.MainTask.Id); tasks[1] = Task.CreateTask(DateTime.Now, DateTime.Now.AddDays(5), urgencies[1].UrgencyName, importancies[2].ImportanceName, importancies[2], urgencies[1], criterias[1].Id, criterias[1], "task 2", tree.MainTask, tree.MainTask.Id); tasks[2] = Task.CreateTask(DateTime.Now, DateTime.Now.AddDays(5), urgencies[2].UrgencyName, importancies[1].ImportanceName, importancies[1], urgencies[2], criterias[2].Id, criterias[2], "task 3", tasks[0], tasks[0].Id); tasks[3] = Task.CreateTask(DateTime.Now, DateTime.Now.AddDays(5), urgencies[0].UrgencyName, importancies[0].ImportanceName, importancies[0], urgencies[0], criterias[0].Id, criterias[0], "task 4", tasks[1], tasks[1].Id); var intervals = new Interval[] { Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(3)), Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(5)), Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(7)), Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(13)), Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(22)), Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(50)) }; var schedules = new Models.Schedule[] { Models.Schedule.CreateSchedule(intervals[0],intervals[1],intervals[2],intervals[3],intervals[4],intervals[5],intervals[0], "first"), Models.Schedule.CreateSchedule(intervals[1],intervals[2],intervals[3],intervals[4],intervals[5],intervals[0],intervals[1], "second"), Models.Schedule.CreateSchedule(intervals[2],intervals[3],intervals[4],intervals[5],intervals[0],intervals[1],intervals[0], "third") }; var timeRules = new TimeRule[] { TimeRule.CreateTimeRule(false, schedules[0].Id, schedules[0]), TimeRule.CreateTimeRule(true, schedules[1].Id, schedules[1]), TimeRule.CreateTimeRule(false, schedules[2].Id, schedules[2]), TimeRule.CreateTimeRule(true, schedules[0].Id, schedules[0]), }; var steps = new Step[] { Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[0].ImportanceName, importancies[0], criterias[2].Id, criterias[2], timeRules[1].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 0), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[1].ImportanceName, importancies[1], criterias[1].Id, criterias[1], timeRules[2].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 1), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[2].ImportanceName, importancies[2], criterias[0].Id, criterias[0], timeRules[3].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 2), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[0].ImportanceName, importancies[0], criterias[1].Id, criterias[1], timeRules[0].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 3), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[2].ImportanceName, importancies[2], criterias[2].Id, criterias[2], timeRules[1].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 4), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[1].ImportanceName, importancies[1], criterias[0].Id, criterias[0], timeRules[2].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 5), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[0].ImportanceName, importancies[0], criterias[0].Id, criterias[0], timeRules[3].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 6), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[1].ImportanceName, importancies[1], criterias[0].Id, criterias[0], timeRules[0].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 7), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[2].ImportanceName, importancies[2], criterias[2].Id, criterias[2], timeRules[1].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 0), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[0].ImportanceName, importancies[0], criterias[0].Id, criterias[0], timeRules[2].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 1), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[2].ImportanceName, importancies[2], criterias[1].Id, criterias[1], timeRules[3].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 2), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[1].ImportanceName, importancies[1], criterias[0].Id, criterias[0], timeRules[0].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 3), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[0].ImportanceName, importancies[0], criterias[0].Id, criterias[0], timeRules[1].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 4), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[1].ImportanceName, importancies[1], criterias[2].Id, criterias[2], timeRules[2].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 5), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[2].ImportanceName, importancies[2], criterias[0].Id, criterias[0], timeRules[3].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 6), Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[0].ImportanceName, importancies[0], criterias[0].Id, criterias[0], timeRules[0].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 7) }; }
public void EditSchedule(Models.Schedule schedule) { scheduleRepo.Update(schedule); }
public Models.Schedule FindSchedule(int id) { Models.Schedule schedule = scheduleRepo.Find(id); return(schedule); }
public void CreateSchedule(Models.Schedule schedule) { RE.Schedules.AddObject(schedule); RE.SaveChanges(); }
public void AddSchedule(Models.Schedule schedule) { //scheduleRepo.AddSchedule(schedule); scheduleRepo.Create(schedule); }
public async Task <Models.Schedule> UpdateSchedule(int id, [FromBody] Models.Schedule schedule) => await _scheduleUnitOfWork.Repository.Update(id, schedule);