private async void DeleteTeacher() { TeacherEx teacherExss = SelectedUser as TeacherEx; //interresant. Alle personer kan findes ved at typecast fra user. // TeacherEx teacherExss = ObjectHolder.Instance.TeacherList.FirstOrDefault(te => te.Id == selectedUser.Id); if (teacherExss.ClassList.Count != 0) { var okornot = MessageBox.Show("Du kan ikke slette denne underviser, idet den har elever knyttet til sig." + "du skal derfor først tilknytte en ny klasse til dine elever i denne klasse.\n" + "Et nyt view vil åbnes, hvis du trykker ok.", "Sletning", MessageBoxButton.OKCancel); if (okornot == MessageBoxResult.OK) { DeleteView deleteView = new DeleteView(null, teacherExss); deleteView.WindowStartupLocation = WindowStartupLocation.CenterScreen; deleteView.ShowDialog(); deleteView.Closing += deleteView_Closing; } } else if (teacherExss.ClassList.Count == 0) { await AreYouSureYouWantToDeleteUser(SelectedUser.Userrole); // vigtigt fordi den ellers g[r ind og lukker forbindelsen for sletningen af underviseren, hvis der ikke er tilknyttet born til ham. } await GetTeachers(); await GetClasses(); }
public DeleteView(ClassEx selectedClassEx = null, TeacherEx selectedTeacher = null) // tjek om det er teacherex eller class { InitializeComponent(); if (viewModel == null) { viewModel = new DeleteViewModel(); } if (selectedClassEx != null) // er det teacher eller class der ønskes slettet? { viewModel.ViewstateObject = Enums.ViewstateObject.Class; viewModel.CurrentClass = selectedClassEx; datagridClassesEx.Visibility = Visibility.Hidden; cbListofTeachers.Visibility = Visibility.Hidden; butAssociate.Visibility = Visibility.Hidden; } else if (selectedTeacher != null) { viewModel.ViewstateObject = Enums.ViewstateObject.Teacher; viewModel.CurrentTeacherEx = selectedTeacher; listboxStudents.Visibility = Visibility.Hidden; cbListofClasses.Visibility = Visibility.Hidden; } DataContext = viewModel; InitializeEvents(); }
public Task <bool> InsertTeacher(TeacherEx teacher)//man gør dette fordi man vil have synkrone kald og ikke asykrone kald. { var tcs = new TaskCompletionSource <bool>(); EventHandler <InsertTeacherCompletedEventArgs> handler = null; handler = (sender, args) => { if (args.UserState == tcs) { service.InsertTeacherCompleted -= handler; if (args.Error != null) { tcs.TrySetException(args.Error); } else if (args.Cancelled) { tcs.TrySetCanceled(); } else { tcs.TrySetResult(args.Result); } } }; service.InsertTeacherCompleted += handler; service.InsertTeacherAsync(teacher, tcs); return(tcs.Task); }
public string GetAssociatedClasses(User user) { TeacherEx employee = (TeacherEx)user; StringBuilder stringBuilder = new StringBuilder(); if (employee != null) { if (employee.ClassList.Count == 0) { stringBuilder.AppendLine("Denne ansat er ikke tilknyttet nogen klasse."); } else { stringBuilder.AppendLine("De tilknyttede klasser for ansat:" + employee.Firstname + " er:"); stringBuilder.AppendLine(); foreach (ClassEx classEx in employee.ClassList) { stringBuilder.AppendLine(classEx.Name); } } } return(stringBuilder.ToString()); }
public async Task <bool> CreateTeacher(TeacherEx teacher) { teacher.Lastlogin = DateTime.Now; teacher.Password = PasswordHash.CreateHash(teacher.Birthdate); // spørgsmålet er om det hele ikke bare skal være på webservicen?? altså genereing af pass og lastlogin. await ServiceProxy.Instance.InsertTeacher(teacher); return(true); }
/* public int GetMostRecentUserId() * { * return DatabaseHandler.Instance.GetMostRecentUserId(); * }*/ public bool InsertTeacher(TeacherEx teacher) { bool success = false; if (teacher.Id != 0) // update { success = DatabaseHandler.Instance.UpdateTeacher(teacher); } else { success = DatabaseHandler.Instance.InsertTeacher(teacher); // will insert into User and Teacher. } return(success); }
public List <TeacherEx> GetTeachers() { List <TeacherEx> teachers = new List <TeacherEx>(); try { DB.Open(); string[][] getTeachers = DB.Query("SELECT [User].Id, [USER].Firstname, [User].Lastname,[User].City, [User].Address," + " [User].Birthdate,[User].Username, [User].Password, [User].Lastlogin, [User].Userrole, [User].PhoneNumber, [User].Email" + " FROM [Teacher] INNER JOIN [User] ON [Teacher].Id=[User].Id ORDER BY [User].Firstname;"); for (int i = 0; i < getTeachers.Length; i++) { TeacherEx teacher = new TeacherEx(); teacher.Id = Convert.ToInt32(getTeachers[i][0]); teacher.Fkuserid = Convert.ToInt32(getTeachers[i][0]); teacher.Firstname = getTeachers[i][1]; teacher.Lastname = getTeachers[i][2]; teacher.City = getTeachers[i][3]; teacher.Address = getTeachers[i][4]; teacher.Birthdate = getTeachers[i][5]; teacher.Username = getTeachers[i][6]; teacher.Password = getTeachers[i][7]; if (getTeachers[i][8] == "") { getTeachers[i][8] = DateTime.MinValue.ToString(); } teacher.Lastlogin = Convert.ToDateTime(getTeachers[i][8]); teacher.Userrole = Convert.ToInt32(getTeachers[i][9]); teacher.Phonenumber = Convert.ToInt32(getTeachers[i][10]); teacher.Email = getTeachers[i][11]; teachers.Add(teacher); } } catch (Exception ex) { } finally { DB.Close(); } return(teachers); }
public bool UpdateTeacher(TeacherEx teacher) { bool success = true; try { DB.Open(); DB.Exec("UPDATE [User] SET Firstname ='" + teacher.Firstname + "', Lastname='" + teacher.Lastname + "', City='" + teacher.City + "', Address='" + teacher.Address + "'," + "Birthdate='" + teacher.Birthdate + "', Username='******', Password='******', Lastlogin ='******', Userrole=" + teacher.Userrole + ", PhoneNumber=" + teacher.Phonenumber + ", Email='" + teacher.Email + "' WHERE Id=" + teacher.Id + ";"); DB.Exec("UPDATE [Teacher] SET [Rank]=" + teacher.Rank + " WHERE Id=" + teacher.Id + ";"); } catch (Exception) { Debug.Write("Fejl!"); success = false; } return(success); }
public TeacherCuView(TeacherEx teacher = null) // se nok mere teacher som generics objekt { InitializeComponent(); if (viewModel == null) { viewModel = new TeacherCuViewModel(); } viewModel.Viewstate = teacher == null ? Enums.ViewState.Create : Enums.ViewState.Edit; if (teacher != null) { viewModel.CurrentTeacher = teacher; // vigtig eftersom jeg ikke får smidt de data som kom fra objektet med ind. Viewstate sættes i starten til create. Er efter linien ovenover blevet sat til edit. } this.DataContext = viewModel; InitializeEvents(); }
public async void Confirm(Object o) { Isloading = true; bool success = false; if (Viewstate == Enums.ViewState.Create) { TeacherEx teacher = new TeacherEx(); teacher.Firstname = firstname; teacher.Lastname = lastname; teacher.City = city; teacher.Birthdate = birthdate; teacher.Address = address; if (selectedRank == "Underviser") { teacher.Userrole = (int)Enums.Userrole.Teacher; } else if (selectedRank == "Vikar") { teacher.Userrole = (int)Enums.Userrole.Substitute; } else if (selectedRank == "Skoleleder") { teacher.Userrole = (int)Enums.Userrole.Principal; } // teacher.Userrole = (int)Enums.Userrole.Teacher; // it's in the view of teacher meaning the userrole will be 1. teacher.Phonenumber = phonenumber; teacher.Email = email; success = await BusinessLogic.Instance.CreateTeacher(teacher); } else if (Viewstate == Enums.ViewState.Edit) // for next week! { // her vil det ikke være nødvendigt at oprette password, id og username. // der skal tjekkes på om værdierne i tekstboksene er blevet ændret. // sørg for at currentteacher kan være en ny instans. Så sparer du dette redudante udtryk.. saml attributterne der bliver sat til objektet. CurrentTeacher.Firstname = firstname; CurrentTeacher.Lastname = lastname; CurrentTeacher.City = city; CurrentTeacher.Birthdate = birthdate; CurrentTeacher.Address = address; if (selectedRank == "Underviser") { CurrentTeacher.Userrole = (int)Enums.Rank.Teacher; } else if (selectedRank == "Vikar") { CurrentTeacher.Userrole = (int)Enums.Rank.Substitute; } else if (selectedRank == "Skoleleder") { CurrentTeacher.Userrole = (int)Enums.Rank.Principal; } CurrentTeacher.Phonenumber = phonenumber; CurrentTeacher.Email = email; success = await BusinessLogic.Instance.UpdateTeacher(CurrentTeacher); } Isloading = false; MessageBox.Show(success ? "Underviser er oprettet/opdateret! Vinduet lukkes." : "Noget gik galt. Underviseren er ikke blevet oprettet/opdateret. Vinduet lukkes."); OnTeacherViewClose(); }
public async Task <bool> UpdateTeacher(TeacherEx teacher) { await ServiceProxy.Instance.InsertTeacher(teacher); return(true); }