Exemplo n.º 1
0
        public void UpdateGradeDistribution(GradeDistribution gradeDistribution, ref List <string> errors)
        {
            if (gradeDistribution == null)
            {
                errors.Add("Grade Distribution cannot be null");
                throw new ArgumentException();
            }

            if (gradeDistribution.Schedule_id < 0)
            {
                errors.Add("Invalid Schedule ID");
            }

            if (string.IsNullOrEmpty(gradeDistribution.Grade_Distribution))
            {
                errors.Add("Invalid Grade Distribution");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(gradeDistribution.Title))
            {
                errors.Add("Invalid Grade Distribution");
                throw new ArgumentException();
            }

            this.repository.UpdateGradeDistribution(gradeDistribution, ref errors);
        }
        public void InsertGradeDistribution(GradeDistribution gradeDistribution, ref List <string> errors)
        {
            var conn = new SqlConnection(ConnectionString);

            try
            {
                var adapter = new SqlDataAdapter(InsertGradeDistributionInfo, conn)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };

                adapter.SelectCommand.Parameters.Add(new SqlParameter("@schedule_id", SqlDbType.Int));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@grade_distribution", SqlDbType.VarChar, 50));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@title", SqlDbType.VarChar, 50));

                adapter.SelectCommand.Parameters["@schedule_id"].Value        = gradeDistribution.Schedule_id;
                adapter.SelectCommand.Parameters["@grade_distribution"].Value = gradeDistribution.Grade_Distribution;
                adapter.SelectCommand.Parameters["@title"].Value = gradeDistribution.Title;

                var dataSet = new DataSet();
                adapter.Fill(dataSet);
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            GradeDistribution gradeDistribution = db.GradeDistributions.Find(id);

            db.GradeDistributions.Remove(gradeDistribution);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "GradeDistributionID,Name,EffectiveDate")] GradeDistribution gradeDistribution)
 {
     if (ModelState.IsValid)
     {
         db.Entry(gradeDistribution).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(gradeDistribution));
 }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "GradeDistributionID,Name,EffectiveDate")] GradeDistribution gradeDistribution)
        {
            if (ModelState.IsValid)
            {
                db.GradeDistributions.Add(gradeDistribution);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(gradeDistribution));
        }
Exemplo n.º 6
0
        // GET: GradeDistributions/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GradeDistribution gradeDistribution = db.GradeDistributions.Find(id);

            if (gradeDistribution == null)
            {
                return(HttpNotFound());
            }
            return(View(gradeDistribution));
        }
Exemplo n.º 7
0
        public string InsertGradeDistribution(GradeDistribution gradeDistribution)
        {
            var errors     = new List <string>();
            var repository = new GradeDistributionRepository();
            var service    = new GradeDistributionService(repository);

            service.InsertGradeDistribution(gradeDistribution, ref errors);
            if (errors.Count == 0)
            {
                return("ok");
            }

            return("error");
        }
Exemplo n.º 8
0
        protected void gridSample_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int gradeID = Convert.ToInt32(teacherCourseGradeGrid.DataKeys[e.RowIndex].Value);

            using (var context = new GradebookDataEntities())
            {
                GradeDistribution obj = context.GradeDistributions.First(x => x.GradeID == gradeID);
                //context.Assignments.Where(x => x.GradeID == gradeID).Delete();
                context.GradeDistributions.Remove(obj);
                context.SaveChanges();
                //BindGrid();
                loadTeacherCourseGradeGrid();
                loadTeacherStudentGradesGrid();
            }
        }
        public List <GradeDistribution> GetGradeDistribution(ref List <string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            var gradeDistributionList = new List <GradeDistribution>();

            try
            {
                var adapter = new SqlDataAdapter(GetGradeDistributionInfo, conn)
                {
                    SelectCommand = { CommandType = CommandType.StoredProcedure }
                };

                var dataSet = new DataSet();
                adapter.Fill(dataSet);

                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    return(null);
                }

                for (var i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                {
                    var gradeDistributionContainer = new GradeDistribution
                    {
                        Schedule_id        = Convert.ToInt32(dataSet.Tables[0].Rows[i]["schedule_id"].ToString()),
                        Grade_Distribution = dataSet.Tables[0].Rows[i]["grade_distribution"].ToString(),
                        Title = dataSet.Tables[0].Rows[i]["title"].ToString()
                    };

                    gradeDistributionList.Add(gradeDistributionContainer);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return(gradeDistributionList);
        }
        public void InsertGradeDistributionTest2()
        {
            //// Arrange
            var errors                   = new List <string>();
            var mockRepository           = new Mock <IGradeDistributionRepository>();
            var gradeDistributionService = new GradeDistributionService(mockRepository.Object);
            var gradeDistribution        = new GradeDistribution
            {
                Schedule_id        = -1,
                Grade_Distribution = string.Empty,
                Title = string.Empty
            };

            //// Act
            gradeDistributionService.InsertGradeDistribution(gradeDistribution, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
        public GradeDistribution GetCourseGradeDistribution(int scheduleId, ref List <string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            GradeDistribution gradeDistribution = null;

            try
            {
                var adapter = new SqlDataAdapter(GetCourseGradeDistributionInfo, conn)
                {
                    SelectCommand = { CommandType = CommandType.StoredProcedure }
                };
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@schedule_id", SqlDbType.Int));

                adapter.SelectCommand.Parameters["@schedule_id"].Value = scheduleId;

                var dataSet = new DataSet();
                adapter.Fill(dataSet);

                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    return(null);
                }

                gradeDistribution = new GradeDistribution
                {
                    Schedule_id        = Convert.ToInt32(dataSet.Tables[0].Rows[0]["schedule_id"].ToString()),
                    Grade_Distribution = dataSet.Tables[0].Rows[0]["grade_distribution"].ToString(),
                    Title = dataSet.Tables[0].Rows[0]["title"].ToString()
                };
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return(gradeDistribution);
        }
Exemplo n.º 12
0
        protected void gridSample_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row         = teacherCourseGradeGrid.Rows[e.RowIndex];
            TextBox     txtCategory = row.FindControl("txtCategory") as TextBox;
            TextBox     txtWeight   = row.FindControl("txtWeight") as TextBox;

            if (txtCategory != null && txtWeight != null)
            {
                using (var context = new GradebookDataEntities())
                {
                    int gradeID           = Convert.ToInt32(teacherCourseGradeGrid.DataKeys[e.RowIndex].Value);
                    GradeDistribution obj = context.GradeDistributions.First(x => x.GradeID == gradeID);
                    obj.Category = txtCategory.Text;
                    obj.Weight   = Convert.ToDecimal(txtWeight.Text);
                    context.SaveChanges();
                    teacherCourseGradeGrid.EditIndex = -1;
                    //BindGrid();
                    loadTeacherCourseGradeGrid();
                }
            }
        }