public static List <School> LoadSchools() { Stopwatch watch = Stopwatch.StartNew(); string sql = @"SELECT * FROM dbo.Schools"; List <School> output = AzureDataStore.LoadData <School>(sql); watch.Stop(); Analytics.TrackEvent(nameof(LoadSchools), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
//* Public Methods /// <summary> /// Inserts a new user into the database. /// </summary> /// <param name="user"> /// The user to insert into db. /// The Id, Email, Username, Password, and SchoolId must be non-null. /// </param> /// <returns>true if the user was saved, false if failed.</returns> public static bool AddUser(User user) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"INSERT INTO dbo.Users (Id, Email, Username, Password, SchoolId) VALUES (@Id, @Email, @Username, @Password, @SchoolId)"; bool output = AzureDataStore.SaveData(sql, user) == 1; watch.Stop(); Analytics.TrackEvent(nameof(AddUser), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Returns a list of teachers from a given school. /// </summary> /// <param name="schoolId">The id of the school. (Guid)</param> /// <returns>A list of teachers from a given school.</returns> public static List <Teacher> LoadAllTeachers(Guid schoolId) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"SELECT * FROM dbo.Teachers WHERE SchoolId = @Id"; List <Teacher> output = AzureDataStore.LoadDataWithGuid <Teacher>(sql, schoolId); watch.Stop(); Analytics.TrackEvent(nameof(LoadAllTeachers), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
//* Public Methods /// <summary> /// Inserts a teacher into the db. /// </summary> /// <param name="teacher"> /// The teacher to insert into the db. /// Id, Name, and SchoolId must be non-null. /// </param> /// <returns> /// true if the teacher was inserted, false if not. /// </returns> public static bool AddTeacher(Teacher teacher) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"INSERT INTO dbo.Teachers (Id, Name, SchoolId) VALUES (@Id, @Name, @SchoolId)"; bool output = AzureDataStore.SaveData(sql, teacher) == 1; watch.Stop(); Analytics.TrackEvent(nameof(AddTeacher), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Returns a list of periods that a class has. /// </summary> /// <param name="classId">The Id of the class. (Guid)</param> /// <returns>List of periods that a class has.</returns> public static List <int> LoadPeriods(Guid classId) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"SELECT (Period) FROM dbo.Class_Periods WHERE ClassId = (@Id)"; List <int> output = AzureDataStore.LoadDataWithGuid <int>(sql, classId); watch.Stop(); Analytics.TrackEvent(nameof(LoadPeriods), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Removes a user from enrollment in a class. /// </summary> /// <param name="class"> /// The class you wich the user to unenroll from. /// Id, UserID, and Period must be non-null. /// </param> /// <returns>The number of rows deleted from the db.</returns> public static int UnenrollUserFromClass(Class @class) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"DELETE FROM dbo.Class_Users WHERE ClassId = @Id AND UserId = @UserId AND Period = @Period"; int output = AzureDataStore.DeleteData(sql, @class); watch.Stop(); Analytics.TrackEvent(nameof(UnenrollUserFromClass), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Returns a list of all assignments of a given class and period. /// </summary> /// <param name="class">The class you want the assignments from. Must have non-null Id and Period.</param> /// <returns>List of all assignments of a given class and period.</returns> public static List <Assignment> LoadAssignments(Class @class) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"SELECT * FROM dbo.Assignments WHERE ClassID = @Id AND Period = @Period"; List <Assignment> output = AzureDataStore.LoadDataWithParam <Assignment, Class>(sql, @class); watch.Stop(); Analytics.TrackEvent(nameof(LoadAssignments), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Deletes an assignment from the db. /// </summary> /// <param name="assignment">The assignment you want to delete. Must have non-null Id.</param> /// <returns>The number of rows deleted from the db.</returns> public static int DeleteAssignment(Assignment assignment) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"DELETE FROM dbo.Assignments WHERE Id = @Id"; int output = AzureDataStore.DeleteData(sql, assignment); watch.Stop(); Analytics.TrackEvent(nameof(DeleteAssignment), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
//* Public Methods public static int AddSchool(School school) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"INSERT INTO dbo.Schools (Id, Name, ZipCode) VALUES (@Id, @Name, @ZipCode)"; int output = AzureDataStore.SaveData(sql, school); watch.Stop(); Analytics.TrackEvent(nameof(AddSchool), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Updates the user's password hash with the new one/. /// </summary> /// <param name="user"> /// User to update in the db. Id and Password must be non-null /// </param> /// <returns>true if successful, false if failed.</returns> public static bool UpdateUser(User user) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"UPDATE dbo.Users SET Password = @Password WHERE Id = @Id"; bool output = AzureDataStore.SaveData(sql, user) == 1; watch.Stop(); Analytics.TrackEvent(nameof(UpdateUser), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Returns the name of a school, given it's Id. /// </summary> /// <param name="schoolId">The Id of the school. (Guid)</param> /// <returns>The name of the school. (string)</returns> public static string GetSchoolName(Guid schoolId) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"SELECT Name FROM dbo.Schools WHERE Id = @Id"; string output = AzureDataStore.LoadDataWithGuid <string>(sql, schoolId) .FirstOrDefault(); watch.Stop(); Analytics.TrackEvent(nameof(GetSchoolName), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Returns a User object, given it's Id. /// </summary> /// <param name="userId">The id of the user. (Guid)</param> /// <returns>The user.</returns> public static User LoadUserFromId(Guid userId) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"SELECT * FROM dbo.Users WHERE Id = @Id"; User output = AzureDataStore.LoadDataWithGuid <User>(sql, userId) .FirstOrDefault(); watch.Stop(); Analytics.TrackEvent(nameof(LoadUserFromId), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Returns a user from the db, given the user's email /// </summary> /// <param name="email">The email of the user. (string)</param> /// <returns>The user.</returns> public static User LoadUserFromEmail(string email) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"SELECT Id, Email, Username, Password, SchoolId FROM dbo.Users WHERE Email = @Id"; List <User> users = AzureDataStore.LoadDataWithString <User>(sql, email); User output = users.FirstOrDefault(); watch.Stop(); Analytics.TrackEvent(nameof(LoadUserFromEmail), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Checks whether an email has an account. /// </summary> /// <param name="email">The email to check in the db.s</param> /// <returns>Whether the email has an account. (bool)</returns> public static bool CheckForUser(string email) { Stopwatch watch = Stopwatch.StartNew(); string sql = @"SELECT 1 FROM dbo.Users WHERE Email = @Id"; List <User> result = AzureDataStore.LoadDataWithString <User>(sql, email); bool output = result.Count > 0; watch.Stop(); Analytics.TrackEvent(nameof(CheckForUser), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
//* Public Methods /// <summary> /// Adds a class to db.Classes, and calls PutInClassPeriod() to add /// its period to db.Class_Periods. /// </summary> /// <param name="@class">The class to add to the db.</param> public static bool AddClass(Class @class) { Stopwatch watch = Stopwatch.StartNew(); string sql = @" INSERT INTO dbo.Classes (Id, Period, Name, TeacherId, UserId, SchoolId) VALUES (@Id, @Period, @Name, @TeacherId, @UserId, @SchoolId)"; // Saves the new class to the db int rowsAffected = AzureDataStore.SaveData(sql, @class); bool output = PeriodManager.AddPeriod(@class); watch.Stop(); Analytics.TrackEvent(nameof(AddClass), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
/// <summary> /// Returns a list of classes that a user is enrolled in, given the /// user's Id. /// </summary> /// <param name="userId">The user's Id (Guid)</param> /// <returns>List of classes that the user is enrolled in.</returns> public static List <Class> LoadEnrolledClasses(Guid userId) { Stopwatch watch = Stopwatch.StartNew(); string sql = @" SELECT dbo.Classes.Id, dbo.Class_Users.Period, dbo.Classes.Name, dbo.Classes.TeacherId FROM dbo.Classes JOIN dbo.Class_Users ON dbo.Classes.Id = dbo.Class_Users.ClassId WHERE dbo.Class_Users.UserId = @Id"; List <Class> output = AzureDataStore.LoadDataWithGuid <Class>(sql, userId); watch.Stop(); Analytics.TrackEvent(nameof(LoadEnrolledClasses), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
//* Public Methods /// <summary> /// Adds period to db.Class_Periods with it's respective classId /// </summary> /// <param name="@class"> /// The class that the period belongs to. Must have Id and Period non-null. /// </param> /// <returns> /// Whether or not adding the period to the db was successful. /// </returns> public static bool AddPeriod(Class @class) { Stopwatch watch = Stopwatch.StartNew(); string sql = @" IF NOT EXISTS ( SELECT 1 FROM dbo.Class_Periods WHERE ClassId = @Id AND Period = @Period ) INSERT INTO dbo.Class_Periods (ClassId, Period) VALUES (@Id, @Period)"; bool output = AzureDataStore.SaveData(sql, @class) == 1; watch.Stop(); Analytics.TrackEvent(nameof(AddPeriod), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }
//* Public Methods /// <summary> /// Inserts an assignment into the db. /// </summary> /// <param name="assignment"> /// The assignment you want to put into the db. /// Must have a non-null Id, DueDate, Description, UserId, and Period /// </param> public static Assignment AddAssignment(Assignment assignment) { Stopwatch watch = Stopwatch.StartNew(); assignment.UserId = (Application.Current as App).SignedInUser.Id; assignment.SetClassId(); assignment.SetPeriod(); string sql = @" INSERT INTO dbo.Assignments (Id, DueDate, Description, Name, ClassId, UserId, Period) VALUES (@Id, @DueDate, @Description, @Name, @ClassId, @UserId, @Period)"; int result = AzureDataStore.SaveData(sql, assignment); Assignment output = result == 1 ? assignment : null; watch.Stop(); Analytics.TrackEvent(nameof(AddAssignment), new Dictionary <string, string> { { "ElapsedTime", $"{ watch.ElapsedMilliseconds } ms" } }); return(output); }