Beispiel #1
0
        //* 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);
        }
        //* 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);
        }
        //* 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);
        }
        //* 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);
        }
Beispiel #6
0
        //* 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);
        }
Beispiel #7
0
        //* 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);
        }