public void InsertOrUpdate(Trainee item) { if (item.Id == default(int)) { _context.Trainees.Add(item); } else { _context.Entry(item).State = EntityState.Modified; } }
/// <summary> /// inform the trainee if he passed the test, and sends him temporary license if he did /// </summary> /// <param name="test">the test object</param> /// <param name="trainee">the trainee who took the test</param> public static void SentEmailToTraineeAfterTest(Test test, Trainee trainee) { var subject = test.Passed == true ? "Congratulations for your new license" : "We are sorry to inform you that you didn't pass the test this time"; var message = test.Passed == true ? "You successfully passed the test on " + test.ActualTestTime.ToString("yyyy - MM - dd") + ", now you are allowed to drive" : "you have to take the test again"; var addAttachment = test.Passed == true; SentEmail(addAttachment, trainee.EmailAddress, subject, message, trainee.FirstName + " " + trainee.LastName, "D.M.V"); }
public void UpdateTrainee(Trainee T) { bool[] checkAll = { CheckId(T.TraineeId), CheckAge(T.DateOfBirth, "Trainee") , TraineeInSystem(T.TraineeId) , CheckEmail(T.Email) }; bool clear = checkAll.All(x => x); if (clear) { dal.UpdateTrainee(T); } }
/// <summary> /// delete a trainee from the list /// </summary> /// <param name="trainee"></param> /// <returns>true if seccessfully removed</returns> public bool deleteTrainee(Trainee trainee) { Trainee t = getTrainee(trainee.Id); //if (t == null) // throw new Exception("Trainee with the same id not found..."); if (DataSource.testsList.Exists(ts => ts.TraineeId == trainee.Id)) { throw new Exception("DAL: Test has been determinared for this trainee !!!"); } return(DataSource.traineesList.Remove(t)); }
private void traineeBindingSource_PositionChanged(object sender, EventArgs e) { TaskTraineeBindingSource.Clear(); Trainee trainee = (Trainee)traineeBindingSource.Current; if (trainee != null) { traineeTaskBLO = new TaskTraineeBLO(trainee.FileName); TaskTraineeBindingSource.DataSource = traineeTaskBLO.GetData(); showTaskTainneeError(); } }
public ActionResult Register(Trainee account) { if (ModelState.IsValid) { using (DataContext db = new DataContext()) { db.Trainee.Add(account); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = account.ID + " " + account.Email + "succsfully registered"; } return(View()); }
private void traineeOptions_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem TempBoxItem = new ComboBoxItem(); foreach (var t in Utilities.ReturnTrainees()) { TempBoxItem.Content = t.ToString(); if (traineeOptions.SelectedItem.ToString() == TempBoxItem.ToString()) { thisTrainee = t; break; } } }
public void setTraineeDAL(Trainee trainee) { List <Trainee> traineeListHelp = DS.GetTraineeList(); int index = traineeListHelp.FindIndex(s => s.Id == trainee.Id); if (index != -1) { DataSource.traineesList[index] = trainee; } else { throw new Exception("לא נמצא נבחן כזה במערכת\n"); } }
public bool Add_trainee(Trainee t) { foreach (Trainee item in DataSource.Trainees) { if (item.ID == t.ID) { throw new Exception("Trainee is already in the system"); } } DataSource.Trainees.Add(t); return(true); }
public List <Test> getTestsOfTrainee(Trainee trainee) { List <Test> testsOfTrainee = new List <Test>(); var v = from tests in getTests() orderby tests.TestDate where tests.TraineeId == trainee.IdTrainee select tests; foreach (var item in v) { testsOfTrainee.Add(item); } return(testsOfTrainee); }
public ActionResult Checar(ViewModelTrainee ViewTrainee) { Trainee trainee = BuscarTrainee(ViewTrainee); if (trainee == null) { return(RedirectToAction("Deletar", "Trainee")); } ViewTrainee.SetarCampos(trainee, ListaDeTrainees()); ViewTrainee.Instituicao = trainee.Instituicao; return(View(ViewTrainee)); }
public int Update(Trainee trainee, int Id) { var spName = "SP_UpdateTrainee"; parameters.Add("@Id", Id); parameters.Add("@Name", trainee.Name); parameters.Add("@Phone", trainee.Phone); parameters.Add("@Address", trainee.Address); parameters.Add("@Birth", trainee.Birth); parameters.Add("@Email", trainee.Email); var result = connection.Execute(spName, parameters, commandType: CommandType.StoredProcedure); return(result); }
/// <summary> /// deletes a trainee /// </summary> /// <param name="t"> trainee to delete</param> public void DeleteTrainee(Trainee t) { XElement traineeList = DS.DataSourceXML.TraineeList;//the xElement version of trainees var found = (from d in traineeList.Elements() where (d.Element("TraineeId").Value == t.TraineeId.ToString()) select d).FirstOrDefault();//found = the trainee with this ID, if there is no such a trainee: found = null if (found == null) { throw new Exception("The trainee does not exist so it cannot be deleted"); } found.Remove(); //deletes the trainee DS.DataSourceXML.SaveTrainees(); //saves the trainees file }
// GET: Trainees/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Trainee trainee = db.Trainees.Find(id); if (trainee == null) { return(HttpNotFound()); } return(View(trainee)); }
private void lastTestOfTrainee(Trainee trainee) { if (bl.getTestsOfTrainee(trainee).Count > 0) { Test test = bl.getTestsOfTrainee(trainee).Last(); if (test.TestDate > DateTime.Now) { nextTest.Visibility = Visibility.Visible; testerOfTrainee.DataContext = bl.GetTester(test.TesterId); DateOfTest.DataContext = test; CarTypeTest.DataContext = test; } } }
//********************* Test Func ********************** public void AddTest(Test test) { Trainee trainee = GetTrainee(test.TraineeId); List <Test> traineeTests = new List <Test>(getTestsOfTrainee(trainee)); if (traineeTests.Count > 0) { if (traineeTests.Last().TestDate.AddDays(7) > test.TestDate) { throw new Exception("לא ניתן לקבוע מבחן בטווח של שבוע מהמבחן הקודם"); } } idal.AddTest(test); }
/// <summary> /// Returns true if all of the trainee's properties are valid. /// </summary> /// <param name="trainee">Trainee to be validated</param> /// <returns></returns> public static bool TraineePropertiesValidation(Trainee trainee) { try { if (PersonPropertiesValidation(trainee) == false || IsTesterIdFound(trainee.Id) == true) { return(false); } else if (trainee.FullAge.Years < Configuration.MinimalTraineeAge) { throw new Exception("Trainee must be aged " + Configuration.MinimalTraineeAge.ToString() + " or more"); } //Car type selection validation else if (trainee.CarType == CarTypeEnum.None) { throw new Exception("You must select a car type"); } //Gear type selection validation else if (trainee.GearType == GearTypeEnum.None) { throw new Exception("You must select a gear type"); } //Driving school validation else if (trainee.FullDrivingSchoolDetails == null) { throw new Exception("You must select a driving school"); } //Driving teacher selection validation else if (IsNameFormatValid(trainee.DrivingSchoolTeacher) == false) { throw new Exception("Driving teacher name must start with a letter and contain only letters and spaces."); } //Driving lessons count validation else if (trainee.DrivingLessonsCount < 0) { throw new Exception("Number of driving lessons must be 0 or more"); } else { return(true); } } catch (Exception e) { Console.WriteLine(e); return(false); } }
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { PassBox_passAdmin.Password = ""; PassBox_passOffice.Password = ""; TextBox_TesterID.Text = ""; TextBox_TraineeID.Text = ""; tester = null; trainee = null; try { TabControl tabControl = sender as TabControl; if (tabControl.SelectedIndex == 1) { AdminMainWindowBorder.Visibility = Visibility.Collapsed; AdminPasswordBorder.Visibility = Visibility.Visible; } if (tabControl.SelectedIndex == 2) { OfficeMainWindowBorder.Visibility = Visibility.Collapsed; OfficeStatistics.Visibility = Visibility.Collapsed; OfficePasswordBorder.Visibility = Visibility.Visible; testersCollection = new ObservableCollection <Tester>(bl.GetTestersList()); traineeCollection = new ObservableCollection <Trainee>(bl.GetTraineeList()); testCollection = new ObservableCollection <Test>(bl.GetTestsList()); //ListView_Testers.ItemsSource = testersCollection; } if (tabControl.SelectedIndex == 3) { ExistingTesterMainWindowBorder.Visibility = Visibility.Collapsed; ExistingTesterIDBorder.Visibility = Visibility.Visible; } if (tabControl.SelectedIndex == 4) { ExistingTraineeMainWindowBorder.Visibility = Visibility.Collapsed; ExistingTraineeIDBorder.Visibility = Visibility.Visible; } } catch (DirectoryNotFoundException D) { MessageBox.Show(D.Message, "בעיה בטעינת נתונים", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign); } catch (KeyNotFoundException a) { MessageBox.Show(a.Message, "שגיאה פנימית", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign); } }
// GET: Trainees/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Trainee trainee = db.Trainees.Find(id); if (trainee == null) { return(HttpNotFound()); } //ViewBag.EnrollmentID = new SelectList(db.Trainees, "CourseID", "CourseName", trainee.Enrollments); return(View(trainee)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Trainee trainee = db.Trainees.Find(id); if (trainee == null) { return(HttpNotFound()); } ViewBag.CourseID = new SelectList(db.Courses, "CourseID", "CourseName", trainee.CourseID); return(View(trainee)); }
private List <Tester> GetTestersByCarType() { Trainee trainee = GetTrainee(); if (trainee == null) { return(TestersList); } var result = from tester in TestersList where tester.CarType == trainee.CarType select tester; return(result.ToList()); }
///// <summary> ///// add test to the stock ///// </summary> ///// <param name="t"></param> //List<Tester> availableTesters(Test t) //{ // List<Tester> returnedList = new List<Tester>(); // List<Tester> _testers = myDal.GetListTesters(); // List<Test> Tests = myDal.GetListTests(); // var testers = from item in _testers //build list with all the testers which available in the date // where (item._Schedule[t._DateTest.Hour - 9, (int)(t._DateTest.DayOfWeek)] && (item.Max_Weekly_Tests >= item._weaklyTests) && (item._CarType == t._CarType)) // select item; // foreach (var item in testers) // { // var tests1 = from item1 in Tests //build list which contains all the testers who also dont do another test at this time // where item._IdTester == item1._IdTester && t._DateTest != item1._DateTest // select item; // foreach (var item1 in tests1) // { // returnedList.Add(item1); // } // } // return returnedList; //} //static public bool condition(Test t) //{ // if (t._CarType == Car_Type.Heavy_Truck) //any other condition will be fit // return true; // return false; //} //public delegate bool conditionDelegate(Test t); //public List<Test> TestConditioned() //{ // List<Test> returnedList = new List<Test>(); // List<Test> t = myDal.GetListTests(); // conditionDelegate cond = condition; // foreach (var item in t) // { // if (cond(item)) // returnedList.Add(item); // } // return returnedList; //} /// <summary> /// Grouping testers by experience /// </summary> /// <returns></returns> //public List<Tester> GroupingByExperience() //{ // var returnedList = new List<Tester>(); // List<Tester> t = myDal.GetListTesters(); // var experience = (from w in t // orderby w // group w by w._CarType).ToList(); // returnedList = experience; // foreach (var item in experience) // { // returnedList.Add(item); // } //} /// <summary> /// check if the trainne passed driving test.e /// </summary> /// <param name="t"></param> /// <returns></returns> //public bool IsPassed(Trainee t) //{ // List<Test> testList = myDal.GetListTests(); // foreach() //} int NumOfTests(Trainee t) { int count = 0; List <Test> Tests = myDal.GetListTests(); var tests = from item in Tests where item._IdTrainee == t._IdTrainee select item; foreach (var item in tests) { count++; } return(count); }
public ActionResult Delete(int id) { try { Trainee trainee = db.Trainees.Find(id); db.Trainees.Remove(trainee); db.SaveChanges(); } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. return(RedirectToAction("Delete", new { id = id, saveChangesError = true })); } return(RedirectToAction("Index")); }
private void testOptions_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem TempBoxItem = new ComboBoxItem(); foreach (var t in Utilities.ReturnTests()) { TempBoxItem.Content = t.ToString(); if (testOptions.SelectedItem.ToString() == TempBoxItem.ToString()) { thisTest = t; break; } } thisTrainee = Utilities.ReturnTrainees().Find(t => t.IDNumber == thisTest.TraineeId); }
/// <summary> /// Update relevant properties of Trainee /// </summary> /// <param name="trainee"></param> public void UpdateTrainee(Trainee trainee) { BE.Trainee ExistTrainee = IDAL.GetTraineeCopy(trainee.ID); if (ExistTrainee == null) { throw new KeyNotFoundException("לא נמצא תלמיד שמספרו " + trainee.ID); } if (ExistTrainee.Gender != trainee.Gender || ExistTrainee.BirthDate != trainee.BirthDate || ExistTrainee.Vehicle != trainee.Vehicle || ExistTrainee.GearBoxType != trainee.GearBoxType || ExistTrainee.DrivingSchoolName != trainee.DrivingSchoolName || ExistTrainee.TeacherName != trainee.TeacherName) { throw new KeyNotFoundException("לא ניתן לשנות מידע בסיסי של תלמיד"); } IDAL.UpdateTrainee(trainee); }
//Data manipulations on TRAINEES /// <summary> /// Adds a trainee to the trainee list in the Data Source /// </summary> /// <param name="trainee">Trainee to be added</param> public string AddTrainee(Trainee trainee) { string error = "Failed to add " + trainee.GetName(); if (IsTraineeIdFound(trainee.Id) == true) { return("Id " + trainee.Id + " was already found"); } else if (TraineePropertiesValidation(trainee) == true) { error = m_xamlImp.AddTrainee(trainee); } return(error); }
//return the number of test in which test.studentid==Trainee.id public int numberOfTest(Trainee t) { int counter = 0; //List<Test> l4 = DAL.DataSource.l3; var v = dal.getAllTests(); foreach (Test item in v) { if (item.studentId == t.id) { counter++; } } return(counter); }
public TraineeDetailsWindow() { this.FlowDirection = FlowDirection.RightToLeft; WindowStartupLocation = WindowStartupLocation.CenterScreen; trainee = new Trainee(""); this.DataContext = trainee; InitializeComponent(); DatePicker_BirthDay.DisplayDate = DateTime.Now.AddYears(-20); CombBx_CurrCar.ItemsSource = Enum.GetValues(typeof(BO.CarTypeEnum)); CombBx_CurrCar.SelectedItem = BO.CarTypeEnum.אופנוע; CombBx_Gender.ItemsSource = Enum.GetValues(typeof(BO.GenderEnum)); CombBx_Gender.SelectedItem = BO.GenderEnum.זכר; CmbBx_City.ItemsSource = MainWindow.cities; CmbBx_Street.IsEnabled = false; }
public void readFromNbt(NbtCompound tag) { NbtList list = tag.getList("candidates"); for (int i = 0; i < list.Count; i++) { this.candidates.Add(new Candidate(list.Get <NbtCompound>(i))); } if (tag.hasKey("trainee")) { this.trainee = new Trainee(tag.getCompound("trainee")); this.traineeTrainingTime = tag.getFloat("trainingTime"); } }
private void btn_Save_Click(object sender, EventArgs e) { if (Trainee == null) { Trainee = new Trainee(); } Trainee.firstName = txt_FirstName.Text; Trainee.lastName = txt_LastName.Text; if (CB_Group.SelectedItem != null) { Group g = gs.FindById((int)CB_Group.SelectedValue); Trainee.Group = g; //(Group)CB_Group.SelectedItem; not working!! } SaveClick(this, e); }
private void InitializeTestFields() { Trainee trainee = BLTools.GetTraineeById(m_targetTest.TraineeId); dmvTb.Text = m_targetTest.DMV; InitializeTestCarTypeRadioButtons(); traineeFirstNameTb.Text = trainee.FirstName; traineeLasatNameTb.Text = trainee.LastName; traineeIdTb.Text = trainee.Id; traineeCarTypeTb.Text = trainee.CarType.ToString(); traineeDrivingSchoolTb.Text = m_targetTest.DrivingSchoolFullName; testDateTb.Text = m_targetTest.TestDateStringFormat; testTimeTb.Text = m_targetTest.TestTimeStringFormat; testLocationTb.Text = m_targetTest.TestLocation.ToString(); }