public Task <bool> CreateEnrollment(EnrollmentEx enrollment, List <ParentEx> parents) { var tcs = new TaskCompletionSource <bool>(); EventHandler <CreateEnrollmentCompletedEventArgs> handler = null; handler = (sender, args) => { if (args.UserState == tcs) { service.CreateEnrollmentCompleted -= handler; if (args.Error != null) { tcs.TrySetException(args.Error); } else if (args.Cancelled) { tcs.TrySetCanceled(); } else { tcs.TrySetResult(args.Result); } } }; service.CreateEnrollmentCompleted += handler; service.CreateEnrollmentAsync(enrollment, parents, tcs); return(tcs.Task); }
public Task <bool> InsertStudent(Student student, EnrollmentEx enrollment = null)//man gør dette fordi man vil have synkrone kald og ikke asykrone kald. { var tcs = new TaskCompletionSource <bool>(); EventHandler <InsertStudentCompletedEventArgs> handler = null; handler = (sender, args) => { if (args.UserState == tcs) { service.InsertStudentCompleted -= handler; if (args.Error != null) { tcs.TrySetException(args.Error); } else if (args.Cancelled) { tcs.TrySetCanceled(); } else { tcs.TrySetResult(args.Result); } } }; service.InsertStudentCompleted += handler; service.InsertStudentAsync(student, enrollment, tcs); return(tcs.Task); }
public bool InsertScore(string testScore) // int testId, string startDate, string testTime, int testUser, double testResult { Score score = new Score(); List <ParentEx> parents = new List <ParentEx>(); EnrollmentEx en = new EnrollmentEx(); en.ChildAddress = "Hejsmukke"; en.ChildBirthdate = "android"; en.ChildCity = "android"; en.ChildFirstname = "android"; en.ChildLastname = "android"; en.ChildPhonenumber = 232; en.DateCreated = DateTime.Now.ToString(); en.Fkschoolid = 1; en.Notes = testScore; // dezrialiseres her . /* * score.UserId = testUser; * score.TestTime = testTime; * score.TestDate = startDate; * score.Result = testResult; */ return(DatabaseHandler.Instance.InsertEnrollment(en, parents)); //return true; }
public bool CreateEnrollment(EnrollmentEx enrollment, List <ParentEx> parents) { enrollment.DateCreated = DateTime.Now.ToString(); // for at faa servertiden. mest korrekt. return(DatabaseHandler.Instance.InsertEnrollment(enrollment, parents)); }
public bool InsertStudent(Student student, EnrollmentEx enrollment = null) { bool success = false; string sqlStatement = ""; if (enrollment != null) { List <ParentEnrollment> parentenrollmentlist = DatabaseHandler.Instance.GetParentEnrollment(enrollment.Id); // student.Id = DatabaseHandler.Instance.InsertStudent(student); // hvorfor ikke bare returner string tilbage og så have en commit metode på databasehandler // så kan du sende den samlet sql statement ned til databasen. (Dette behøves ikke når der skal læses/read da den ikke kan ødelægge noget.) transaction sqlStatement += DatabaseHandler.Instance.InsertStudent2(student); foreach (ParentEnrollment parentenrollment in parentenrollmentlist) { StudentParent association = new StudentParent(); association.Fkparentid = parentenrollment.Fkparentid; association.Fkstudentid = student.Id; sqlStatement += DatabaseHandler.Instance.InsertIntoStudentParent2(association); // abner og lukker connection flere gange.... } foreach (ParentEnrollment parentenrollment in parentenrollmentlist) { sqlStatement += DatabaseHandler.Instance.DeleteConnectionBetweenParentAndEnrollment2(parentenrollment.Fkparentid, enrollment.Id); // abner og lukker connection flere gange.... } sqlStatement += DatabaseHandler.Instance.DeleteEnrollment2(enrollment.Id); success = DatabaseHandler.Instance.Commit(sqlStatement); } else if (enrollment == null) { if (student.Id != 0) { success = DatabaseHandler.Instance.UpdateStudent(student); } else { //int recentId = DatabaseHandler.Instance.GetMostRecentUserId(); // if (recentId != -1) //{ /* student.Id = recentId; * student.Fkuserid = recentId; * student.Username = "******" + recentId;*/ int generatedId = DatabaseHandler.Instance.InsertStudent(student); // will insert into User and Student. // } } } return(success); }
public async Task <bool> CreateEnrollment(Repository repository) { try { Student s = new Student(); List <ParentEx> parents = new List <ParentEx>(); EnrollmentEx enrollment = new EnrollmentEx(); enrollment.ChildFirstname = repository.ChildFirstname; enrollment.ChildLastname = repository.ChildLastname; enrollment.ChildCity = repository.ChildCity; enrollment.ChildAddress = repository.ChildAddress; enrollment.ChildPhonenumber = repository.ChildPhonenumber; enrollment.ChildBirthdate = repository.ChildBirthdate; enrollment.Notes = repository.Notes; enrollment.Fkschoolid = 1; // id 1 er for birkealle. if (string.IsNullOrEmpty(repository.FatherUsername) || string.IsNullOrEmpty(repository.MotherUsername)) // the mother and father is not a couple. { if (string.IsNullOrEmpty(repository.MotherUsername)) { parents.Add(new ParentEx { Id = Convert.ToInt32(repository.FatherUsername.Substring(3, repository.FatherUsername.Length - 3)) }); } else if (string.IsNullOrEmpty(repository.FatherUsername)) { parents.Add(new ParentEx { Id = Convert.ToInt32(repository.MotherUsername.Substring(3, repository.MotherUsername.Length - 3)) }); } } else // the mother and father is a coulpe { parents.Add(new ParentEx { Username = repository.MotherUsername, Id = Convert.ToInt32(repository.MotherUsername.Substring(3, repository.MotherUsername.Length - 3)) }); parents.Add(new ParentEx { Username = repository.FatherUsername, Id = Convert.ToInt32(repository.FatherUsername.Substring(3, repository.MotherUsername.Length - 3)) }); } return(await ServiceProxy.Instance.CreateEnrollment(enrollment, parents)); } catch (Exception ex) { return(false); } }
public void InsertEnrollment() { List <ParentEx> parents = new List <ParentEx>(); EnrollmentEx en = new EnrollmentEx(); en.ChildAddress = "Hejsmukke"; en.ChildBirthdate = "android"; en.ChildCity = "android"; en.ChildFirstname = "android"; en.ChildLastname = "android"; en.ChildPhonenumber = 232; en.DateCreated = DateTime.Now.ToString(); en.Fkschoolid = 1; en.Notes = "notetet"; DatabaseHandler.Instance.InsertEnrollment(en, parents); }
public List <EnrollmentEx> GetEnrollments() { List <EnrollmentEx> enrollments = new List <EnrollmentEx>(); try { DB.Open(); string[][] getEnrollments = DB.Query("SELECT * FROM [Enrollment];"); for (int i = 0; i < getEnrollments.Length; i++) { EnrollmentEx enrollment = new EnrollmentEx(); enrollment.Id = Convert.ToInt32(getEnrollments[i][0]); enrollment.ChildFirstname = getEnrollments[i][1]; enrollment.ChildLastname = getEnrollments[i][2]; enrollment.ChildCity = getEnrollments[i][3]; enrollment.ChildAddress = getEnrollments[i][4]; enrollment.ChildBirthdate = getEnrollments[i][5]; enrollment.ChildPhonenumber = Convert.ToInt32(getEnrollments[i][6]); enrollment.Notes = getEnrollments[i][7]; enrollment.DateCreated = getEnrollments[i][8]; enrollment.Fkschoolid = Convert.ToInt32(getEnrollments[i][9]); enrollments.Add(enrollment); } } catch (SqlException ex) { } finally { DB.Close(); } return(enrollments); }
/// <summary> /// Creates a student. Optinal to choose enrollment. If you link an enrollment the student will be created out from that enrollment. /// </summary> public async Task <bool> CreateStudent(string firstname, string lastname, string city, string address, string birthdate, int phonenumber, string email, int fkClassid, EnrollmentEx enrollment = null) { Student student = new Student(); student.Firstname = firstname; student.Lastname = lastname; student.City = city; student.Email = email; student.Birthdate = birthdate; student.Address = address; student.Userrole = (int)Enums.Userrole.Student; student.Phonenumber = phonenumber; student.FkClassid = fkClassid; student.Fkschoolid = schoolId; student.Lastlogin = DateTime.Now; student.Password = PasswordHash.CreateHash(student.Birthdate); return(await ServiceProxy.Instance.InsertStudent(student, enrollment)); }