public void OnCreateTemplateScheduleButtonClicked(TemplateSchedule templateSchedule) { if (CreateTemplateScheduleButtonClicked != null) { CreateTemplateScheduleButtonClicked(templateSchedule); } }
private void BtnSaveUpdatedTemplateSchedule_Click(object sender, RoutedEventArgs e) { TemplateSchedule templateSchedule = (TemplateSchedule)CBoxSchedule.SelectedItem; Mediator.GetInstance().OnTemplateScheduleUpdateButtonClicked(sender, templateSchedule); MessageBox.Show("Changes to: " + templateSchedule.Name + " have been saved to database "); }
public void CreateTemplateScheduleTest() { TemplateSchedule tSchedule = templateScheduleController.CreateTemplateSchedule(10, "basicSchedule"); Assert.IsNotNull(tSchedule); Assert.AreEqual(tSchedule.Name, "basicSchedule"); }
public async Task <int> Insert(TemplateSchedule model) { try { _connection = Connect.Open(); var p = new DynamicParameters(); p.Add("@ScheduleId", model.ScheduleId); p.Add("@TemplateId", model.TemplateId); p.Add("@TemplateScheduleId", dbType: DbType.Int32, direction: ParameterDirection.Output); await _connection.ExecuteAsync("TemplateScheduleInsert", p, commandType : CommandType.StoredProcedure); return(p.Get <int>("@TemplateScheduleId")); } catch (Exception ex) { //MessageBox.Show(ex.Message); throw; } finally { _connection.Dispose(); } }
public void InsertTemplateScheduleTest() { List <TemplateSchedule> templateSchedules = _templateScheduleRepository.GetAllTemplateSchedules().ToList(); int numberOfCurrentTemplateSchedules = templateSchedules.Count; TemplateSchedule templateSchedule = new TemplateSchedule(4, "DummySchedule", 1); _templateScheduleRepository.AddTemplateScheduleToDatabase(templateSchedule); Assert.AreNotEqual(numberOfCurrentTemplateSchedules, _templateScheduleRepository.GetAllTemplateSchedules().Count()); }
/// <summary> /// This method generates a schedule by a template schedule and date. /// </summary> /// <param name="templateSchedule"></param> /// <param name="startTime"></param> /// <returns> /// Returns a schedule object with shifts added. /// </returns> public Schedule GenerateScheduleFromTemplateSchedule(TemplateSchedule templateSchedule, DateTime startTime) { Schedule schedule = new Schedule(); schedule.Shifts = _scheduleShiftController.GenerateShiftsFromTemplateSchedule(templateSchedule, startTime); schedule.Department = _departmentController.GetDepartmentById(templateSchedule.DepartmentId); schedule.StartDate = startTime; schedule.EndDate = startTime.AddDays((7 * templateSchedule.NoOfWeeks) - 1); return(schedule); }
public void AddTemplateScheduleToDbServiceTest() { List <TemplateSchedule> beforeAddingTemplateScheduleList = _templateScheduleService.GetAllTemplateSchedules(); TemplateSchedule templateSchedule = new TemplateSchedule(4, "DummySchedule", 1); _templateScheduleService.AddTemplateScheduleToDb(templateSchedule); List <TemplateSchedule> afterAddingTemplateScheduleList = new List <TemplateSchedule>(_templateScheduleService.GetAllTemplateSchedules()); Assert.AreNotEqual(beforeAddingTemplateScheduleList.Count, afterAddingTemplateScheduleList.Count); }
public void OnTemplateScheduleUpdateButtonClicked(object sender, TemplateSchedule templateSchedule) { var templateScheduleUpdateClicked = TemplateScheduleUpdateClicked as EventHandler <TemplateSelectedArgs>; if (templateScheduleUpdateClicked != null) { templateScheduleUpdateClicked(sender, new TemplateSelectedArgs { TemplateSchedule = templateSchedule }); } }
public TemplateSchedule BuildTemplateScheduleObject(SqlDataReader reader) { TemplateSchedule templateSchedule = new TemplateSchedule(); templateSchedule.Id = reader.GetInt32(0); templateSchedule.Name = reader.GetString(1); templateSchedule.NoOfWeeks = reader.GetInt32(2); templateSchedule.DepartmentId = reader.GetInt32(3); templateSchedule.RowVersion = reader.GetFieldValue <byte[]>(4); return(templateSchedule); }
public void AddTemplateScheduleToDatabaseTest() { TemplateScheduleRepository templateScheduleRepository = new TemplateScheduleRepository(); TemplateSchedule templateSchedule = new TemplateSchedule(4, "DummySchedule", 1); int beforeInsert = templateScheduleRepository.GetAllTemplateSchedules().Count(); templateScheduleRepository.AddTemplateScheduleToDatabase(templateSchedule); int afterInsert = templateScheduleRepository.GetAllTemplateSchedules().Count(); Assert.AreEqual(beforeInsert, (afterInsert - 1)); }
private void ChooseSchedule_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (CBoxSchedule.HasItems) { TemplateSchedule templateSchedule = (TemplateSchedule)CBoxSchedule.SelectedItem; txtWeeks.Text = templateSchedule.NoOfWeeks.ToString(); Mediator.GetInstance().OnTemplateScheduleSelected(sender, templateSchedule); } else { txtWeeks.Text = ""; } }
public void UpdateTemplateScheduleTest() { TemplateSchedule templateSchedule = _templateScheduleRepository.GetAllTemplateSchedules().ToList()[0]; byte[] rowVersion1 = templateSchedule.RowVersion; templateSchedule.NoOfWeeks = 2; _templateScheduleRepository.UpdateTemplateSchedule(templateSchedule); templateSchedule = _templateScheduleRepository.GetAllTemplateSchedules().ToList()[0]; byte[] rowVersion2 = templateSchedule.RowVersion; Assert.AreEqual(2, templateSchedule.NoOfWeeks); Assert.AreNotEqual(rowVersion1, rowVersion2); }
public List <ScheduleShift> GenerateShiftsFromTemplateSchedule(TemplateSchedule templateSchedule, DateTime startTime) { List <ScheduleShift> scheduleShifts = new List <ScheduleShift>(); foreach (TemplateShift templateShift in templateSchedule.TemplateShifts) { ScheduleShift shift = new ScheduleShift(); shift.Employee = templateShift.Employee; shift.Hours = templateShift.Hours; shift.StartTime = startTime.AddDays(((int)templateShift.WeekDay - 1) + (templateShift.WeekNumber - 1) * 7); shift.StartTime = shift.StartTime.AddHours(templateShift.StartTime.Hours); shift.StartTime = shift.StartTime.AddMinutes(templateShift.StartTime.Minutes); scheduleShifts.Add(shift); } return(scheduleShifts); }
public void UpdateTemplateSchedule(TemplateSchedule templateSchedule) { if (ValidateTemplateSchedule(templateSchedule)) { using (TransactionScope scope = new TransactionScope()) { _templateScheduleRepository.UpdateTemplateSchedule(templateSchedule); _templateShiftController.AddTemplateShiftsFromTemplateSchedule(templateSchedule.Id, templateSchedule.TemplateShifts); scope.Complete(); } } else { throw new ArgumentException(); } }
public void GetShiftsFromTemplateShiftTest() { _scheduleController = new ScheduleController(new ScheduleRepository()); Employee employee = new Employee(); TemplateSchedule templateSchedule = _templateScheduleController.CreateTemplateSchedule(10, "basicSchedule"); TemplateShift templateShift = _templateShiftController.CreateTemplateShift(DayOfWeek.Friday, 10.0, new TimeSpan(10, 0, 0), 1, employee); TemplateShift templateShift2 = _templateShiftController.CreateTemplateShift(DayOfWeek.Monday, 15.0, new TimeSpan(3, 1, 2), 2, employee); templateSchedule.TemplateShifts.Add(templateShift); templateSchedule.TemplateShifts.Add(templateShift2); Schedule schedule = _scheduleController.GenerateScheduleFromTemplateSchedule(templateSchedule, DateTime.Now); Assert.AreEqual(templateSchedule.TemplateShifts.Count, schedule.Shifts.Count); Assert.AreEqual(schedule.Shifts[1].Hours, templateSchedule.TemplateShifts[1].Hours); }
public void UpdateTemplateSchedule(TemplateSchedule templateSchedule) { using (SqlConnection connection = new DbConnection().GetConnection()) { using (SqlCommand command = new SqlCommand( "UPDATE TemplateSchedule SET noOfWeeks = @param1 " + "WHERE RV = @param2", connection)) { command.Parameters.AddWithValue("@param1", templateSchedule.NoOfWeeks); command.Parameters.AddWithValue("@param2", templateSchedule.RowVersion); int rowsAffected = command.ExecuteNonQuery(); if (rowsAffected == 0) { throw new DataInInvalidStateException(); } } } }
public int AddTemplateScheduleToDatabase(TemplateSchedule templateSchedule) { int templateScheduleId; using (SqlConnection connection = new DbConnection().GetConnection()) { using (SqlCommand command = new SqlCommand( "INSERT INTO TemplateSchedule (name, NoOfWeeks, departmentID) " + "VALUES (@param1,@param2,@param3) SELECT SCOPE_IDENTITY()", connection)) { command.Parameters.AddWithValue("@param1", templateSchedule.Name); command.Parameters.AddWithValue("@param2", templateSchedule.NoOfWeeks); command.Parameters.AddWithValue("@param3", templateSchedule.DepartmentId); templateScheduleId = Convert.ToInt32(command.ExecuteScalar()); } } return(templateScheduleId); }
private bool ValidateTemplateSchedule(TemplateSchedule templateSchedule) { bool isOkToInsert = true; if (templateSchedule.DepartmentId <= 0) { isOkToInsert = false; } else if (templateSchedule.Name == null || templateSchedule.Name == string.Empty) { isOkToInsert = false; } else if (templateSchedule.NoOfWeeks <= 0) { isOkToInsert = false; } return(isOkToInsert); }
public List <TemplateSchedule> GetAllTemplateSchedules() { List <TemplateSchedule> templateSchedules = new List <TemplateSchedule>(); using (SqlConnection connection = new DbConnection().GetConnection()) { using (SqlCommand command = new SqlCommand("SELECT * FROM TemplateSchedule", connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { TemplateSchedule templateSchedule = BuildTemplateScheduleObject(reader); templateSchedules.Add(templateSchedule); } } } } return(templateSchedules); }
private void BtnSaveTemplateSchedule_Click(object sender, RoutedEventArgs e) { if (TxtBoxTemplateScheduleName.Text.Length == 0) { MessageBox.Show("Please enter name"); } else if (NoOfWeeks.SelectedItem == null) { MessageBox.Show("Please choose number of weeks!"); } else { TemplateSchedule templateSchedule = new TemplateSchedule(); Department selectedDep = (Department)CBoxDepartment.SelectedItem; templateSchedule.DepartmentId = selectedDep.Id; templateSchedule.NoOfWeeks = (int)NoOfWeeks.SelectedItem; templateSchedule.Name = TxtBoxTemplateScheduleName.Text; Mediator.GetInstance().OnCreateTemplateScheduleButtonClicked(templateSchedule); } }
private void BtnGenerateSchedule_Click(object sender, RoutedEventArgs e) { if (DatePicker.SelectedDate != null && ListTemplateSchedule.SelectedIndex != -1) { try { TemplateSchedule templateSchedule = (TemplateSchedule)ListTemplateSchedule.SelectedItem; DateTime startTime = (DateTime)DatePicker.SelectedDate; Schedule schedule = new ScheduleProxy().GenerateScheduleFromTemplateScheduleAndStartDate(templateSchedule, startTime); Mediator.GetInstance().OnGenerateScheduleButtonClicked(schedule); BtnPublishSchedule.IsEnabled = true; } catch (Exception) { MessageBox.Show("Could not generate Schedule! Please check all parameters and try again"); } } else { MessageBox.Show("Please select both, department, templateschedule and start date"); } }
public async Task Update(TemplateSchedule model) { try { _connection = Connect.Open(); var p = new DynamicParameters(); p.Add("@TemplateScheduleId", model.TemplateScheduleId); p.Add("@ScheduleId", model.ScheduleId); p.Add("@TemplateId", model.TemplateId); await _connection.ExecuteAsync("TemplateScheduleUpdate", p, commandType : CommandType.StoredProcedure); } catch (Exception ex) { //MessageBox.Show(ex.Message); throw; } finally { _connection.Dispose(); } }
public Task <Schedule> GenerateScheduleFromTemplateScheduleAndStartDateAsync(TemplateSchedule templateSchedule, DateTime startTime) { throw new NotImplementedException(); }
public Task UpdateTemplateScheduleWithDeleteAsync(TemplateSchedule templateSchedule, List <TemplateShift> deletedTemplateShifts) { return(_templateScheduleServiceClient.UpdateTemplateScheduleWithDeleteAsync(templateSchedule, deletedTemplateShifts)); }
public Schedule GenerateScheduleFromTemplateScheduleAndStartDate(TemplateSchedule templateSchedule, DateTime startTime) { return(_scheduleController.GenerateScheduleFromTemplateSchedule(templateSchedule, startTime)); }
public void UpdateTemplateScheduleWithDelete(TemplateSchedule templateSchedule, List <TemplateShift> deletedTemplateShifts) { _templateScheduleController.UpdateTemplateSchedule(templateSchedule, deletedTemplateShifts); }
public void AddTemplateScheduleToDb(TemplateSchedule templateSchedule) { _templateScheduleController.AddTemplateScheduleToDb(templateSchedule); }
public Schedule GenerateScheduleFromTemplateScheduleAndStartDate(TemplateSchedule templateSchedule, DateTime startTime) { return(_scheduleServiceClient.GenerateScheduleFromTemplateScheduleAndStartDate(templateSchedule, startTime)); }
public void UpdateTemplateSchedule(TemplateSchedule templateSchedule) { _templateScheduleController.UpdateTemplateSchedule(templateSchedule); }
public Task <Schedule> GenerateScheduleFromTemplateScheduleAndStartDateAsync(TemplateSchedule templateSchedule, DateTime startTime) { return(_scheduleServiceClient.GenerateScheduleFromTemplateScheduleAndStartDateAsync(templateSchedule, startTime)); }