Exemplo n.º 1
0
        public int DeleteRubric(RubricObject rubric)
        {
            try
            {
                string delQuery = "DELETE FROM [dbo].[rubric_tbl] WHERE rubricId = (@RubricId);";

                sqlParameters = new List <SqlParameter>();
                SqlParameter param1 = new SqlParameter("@RubricId", SqlDbType.Int, int.MaxValue, "rubricId");
                param1.Value = rubric.RubricId;

                sqlParameters.Add(param1);

                if (param1.Value == null)
                {
                    throw new MyException();
                }
                else
                {
                    adminDataAccess = new DataAccess();
                    Task <int> task = Task.Run(() => adminDataAccess.ExecuteCommandAsync(delQuery, CommandType.Text, sqlParameters));

                    return(task.Result);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public int UpdateRubric(RubricObject rubric)
        {
            try
            {
                string updQuery = "$UPDATE [dbo].[rubric_tbl] SET rubricName = @RubricName, minGrade = @MinGrade, maxCriteria = @MaxGrade, averageGrade = @AverageGrade, maxCriteria = @MaxCriteria, classId = @Class where rubricId = @RubricId";

                SqlParameter param1, param2, param3, param4, param5, param6;

                param1       = new SqlParameter("@RubricName", SqlDbType.NVarChar, 50, "rubricName");
                param1.Value = rubric.RubricName;

                param2       = new SqlParameter("@MinGrade", SqlDbType.Int, int.MaxValue, "maxCriteria");
                param2.Value = rubric.MinGrade;

                param3       = new SqlParameter("@MaxGrade", SqlDbType.Int, int.MaxValue, "maxCriteria");
                param3.Value = rubric.MaxGrade;

                param4       = new SqlParameter("@MaxCriteria", SqlDbType.Int, int.MaxValue, "maxCriteria");
                param4.Value = rubric.MaxCriteria;

                param5       = new SqlParameter("@Class", SqlDbType.Int, int.MaxValue, "classId");
                param5.Value = rubric.Class.ClassId;

                param6       = new SqlParameter("@RubricId", SqlDbType.Int, int.MaxValue, "rubricId");
                param6.Value = rubric.RubricId;

                if (param6.Value == null)
                {
                    throw new NullReferenceException();
                }
                else
                {
                    sqlParameters = new List <SqlParameter>();
                    sqlParameters.Add(param1);
                    sqlParameters.Add(param2);
                    sqlParameters.Add(param3);
                    sqlParameters.Add(param4);
                    sqlParameters.Add(param5);
                    sqlParameters.Add(param6);

                    adminDataAccess = new DataAccess();

                    Task <int> task = Task.Run(() => adminDataAccess.ExecuteCommandAsync(updQuery, CommandType.Text, sqlParameters));

                    return(task.Result);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        public int AddRubric(RubricObject rubric)
        {
            try
            {
                string insQuery = $"INSERT INTO [dbo].[rubric_tbl] (rubricName, minGrade, maxGrade, averageGrade, maxCriteria, classId) VALUES(@RubricName, @MinGrade, @MaxGrade, @AverageGrade,@MaxCriteria, @ClassId)";

                SqlParameter param1, param2, param3, param4, param5, param6;

                param1       = new SqlParameter("@RubricName", SqlDbType.NVarChar, 50, "rubricName");
                param1.Value = rubric.RubricName;

                param2       = new SqlParameter("@MinGrade", SqlDbType.Int, 50, "minGrade");
                param2.Value = rubric.MinGrade;

                param3       = new SqlParameter("@MaxGrade", SqlDbType.Int, 50, "maxGrade");
                param3.Value = rubric.MaxGrade;

                param4       = new SqlParameter("@AverageGrade", SqlDbType.Int, 50, "averageGrade");
                param4.Value = rubric.AverageGrade;

                param5       = new SqlParameter("@MaxCriteria", SqlDbType.Int, 50, "maxCriteria");
                param5.Value = rubric.MaxCriteria;

                param6       = new SqlParameter("@ClassId", SqlDbType.Int, int.MaxValue, "classId");
                param6.Value = rubric.Class.ClassId;

                sqlParameters = new List <SqlParameter>();

                sqlParameters.Add(param1);
                sqlParameters.Add(param2);
                sqlParameters.Add(param3);
                sqlParameters.Add(param4);
                sqlParameters.Add(param5);
                sqlParameters.Add(param6);

                adminDataAccess = new DataAccess();

                Task <int> task = Task.Run(() => adminDataAccess.ExecuteCommandAsync(insQuery, CommandType.Text, sqlParameters));

                return(task.Result);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 4
0
        public RubricObject ViewRubric(int rubricId)
        {
            try
            {
                string sqlSelect = $"SELECT [rubricId] ,[rubricName] ,[minGrade] ,[maxGrade] ,[averageGrade] ,[maxCriteria] , r.[classId], cl.className FROM[dbo].[rubric_tbl] r join class_tbl cl on r.classId = cl.classId where rubricId = @RubricId;";

                parameters = new List <ParameterList>();
                parameters.Add(new ParameterList()
                {
                    Key = "@RubricId", Value = rubricId
                });

                RubricObject rubricObj = new RubricObject();
                adminDataAccess = new DataAccess();

                Task <DataTable> task = Task.Run(() => adminDataAccess.GetDataAsync(sqlSelect, parameters));

                rubricObj.RubricId        = Convert.ToInt32(task.Result.Columns["rubricId"]);
                rubricObj.RubricName      = task.Result.Columns["rubricName"].ToString();
                rubricObj.MinGrade        = Convert.ToInt32(task.Result.Columns["minGrade"]);
                rubricObj.MaxGrade        = Convert.ToInt32(task.Result.Columns["maxGrade"]);
                rubricObj.MaxCriteria     = Convert.ToInt32(task.Result.Columns["maxCriteria"]);
                rubricObj.Class.ClassId   = Convert.ToInt32(task.Result.Columns["classId"]);
                rubricObj.Class.ClassName = task.Result.Columns["className"].ToString();

                if (rubricObj == null)
                {
                    throw new NullReferenceException();
                }
                else
                {
                    return(rubricObj);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }