예제 #1
0
 public ActionResult DeleteConfirmed(int id)
 {
     LetterGrade letterGrade = db.LetterGrades.Find(id);
     db.LetterGrades.Remove(letterGrade);
     db.SaveChanges();
     return RedirectToAction("Index");
 }
예제 #2
0
        /// <summary>
        /// Deletes the specified LetterGrade
        /// </summary>
        /// <returns></returns>
        public int Delete(LetterGrade letterGrade)
        {
            SqlConnection conn = this.CreateSqlConnection();

            try
            {
                this.InitializeConnection(conn);
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = String.Format(@"DELETE FROM [{0}].[LetterGrade] 
                                    WHERE  [LetterGradeId] = @LetterGradeId", this.Schema);


                if (ReferenceEquals(letterGrade.LetterGradeId, null))
                {
                    cmd.Parameters.AddWithValue("@LetterGradeId", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@LetterGradeId", letterGrade.LetterGradeId);
                }


                int rowsAffected = cmd.ExecuteNonQuery();

                return(rowsAffected);
            }
            finally
            {
                conn.Close();
            }
        }
예제 #3
0
        /// <summary>
        /// Returns a count of the numbers of rows affected by the Upsert.
        /// </summary>
        /// <param name="person"></param>
        /// <param name="dataSource"></param>
        /// <param name="dbName"></param>
        /// <returns></returns>
        public int Upsert(LetterGrade letterGrade)
        {
            SqlConnection conn = this.CreateSqlConnection();

            try
            {
                this.InitializeConnection(conn);
                SqlCommand cmd = conn.CreateCommand();

                // Check if this method exists, and call insert or udpate as appropriate


                var id = letterGrade.LetterGradeId;
                cmd.CommandText = String.Format(@"SELECT CASE WHEN EXISTS (SELECT * FROM [LetterGrade] WHERE LetterGradeId = '{0}') THEN 1 else 0 END", id);

                var rowExists = cmd.ExecuteScalar();

                if (rowExists.SafeToString() == "1")
                {
                    return(this.Update(letterGrade));
                }
                else
                {
                    return(this.Insert(letterGrade));
                }
            }
            finally
            {
                conn.Close();
            }
        }
            internal static LetterGrade FromCsv(string line)
            {
                var parts = line.Split(",".ToCharArray());
                var rv    = new LetterGrade();

                rv.Letter = parts[0];
                rv.Points = double.Parse(parts[1]);
                return(rv);
            }
예제 #5
0
 public ActionResult Edit([Bind(Include = "LetterGradeID,Grade,MinGrade,MaxGrade")] LetterGrade letterGrade)
 {
     if (ModelState.IsValid)
     {
         db.Entry(letterGrade).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(letterGrade));
 }
 /// <summary>
 /// Updates a specific LetterGrade based on it's ID
 /// </summary>
 /// <returns>LetterGrade</returns>
 public LetterGrade Put([FromBody] LetterGrade lettergrade)
 {
     if (String.IsNullOrEmpty(lettergrade.LetterGradeId))
     {
         lettergrade.LetterGradeId = Guid.NewGuid().ToString();
     }
     this.OnBeforePut(lettergrade);
     this.SDM.Upsert(lettergrade);
     this.OnAfterPut(lettergrade);
     return(lettergrade);
 }
        public void CalculateReturnsApproprateGrade(int numberGrade, LetterGrade letterGrade)
        {
            // Arrange
            var sut = new GradeCalculator();

            // Act
            var result = sut.Calculate(numberGrade);

            // Assert
            Assert.Equal(letterGrade, result);
        }
예제 #8
0
        public ActionResult Create([Bind(Include = "LetterGradeID,Grade,MinGrade,MaxGrade")] LetterGrade letterGrade)
        {
            if (ModelState.IsValid)
            {
                db.LetterGrades.Add(letterGrade);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(letterGrade));
        }
예제 #9
0
 // GET: LetterGrades/Delete/5
 public ActionResult Delete(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     LetterGrade letterGrade = db.LetterGrades.Find(id);
     if (letterGrade == null)
     {
         return HttpNotFound();
     }
     return View(letterGrade);
 }
예제 #10
0
        /// <summary>
        /// Initializes the <see cref="EnrolledCourseArgs"/> data into the <see cref="EnrolledCourse"/> object
        /// </summary>
        /// <param name="args"></param>
        public EnrolledCourse(EnrolledCourseArgs args)
        {
            var cArgs = ObjectCache.CourseRootList.FirstOrDefault(c => c.CourseID == args.CourseID);

            if (cArgs == null)
            {
                return;
            }
            info         = new Course(cArgs);
            courseID     = args.CourseID;
            courseNumber = args.CourseNumber;
            semester     = (SemesterType)args.Semester;
            year         = args.Year;
            grade        = (LetterGrade)args.Grade;
        }
예제 #11
0
        /// <summary>
        /// Updates the specified LetterGrade
        /// </summary>
        /// <returns></returns>
        public int Update(LetterGrade letterGrade)
        {
            SqlConnection conn = this.CreateSqlConnection();

            try
            {
                this.InitializeConnection(conn);
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = String.Format(@"UPDATE [{0}].[LetterGrade] SET 
                                    [Name] = @Name, [PointMin] = @PointMin, [PointMincopy] = @PointMincopy, [createdTime] = @createdTime, [Notes] = @Notes
                                    WHERE  [LetterGradeId] = @LetterGradeId", this.Schema);

                //TEXT

                if (ReferenceEquals(letterGrade.LetterGradeId, null))
                {
                    cmd.Parameters.AddWithValue("@LetterGradeId", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@LetterGradeId", letterGrade.LetterGradeId);
                }
                //TEXT

                if (ReferenceEquals(letterGrade.Name, null))
                {
                    cmd.Parameters.AddWithValue("@Name", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@Name", letterGrade.Name);
                }
                //INT32

                if (ReferenceEquals(letterGrade.PointMin, null))
                {
                    cmd.Parameters.AddWithValue("@PointMin", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@PointMin", letterGrade.PointMin);
                }
                //INT32

                if (ReferenceEquals(letterGrade.PointMincopy, null))
                {
                    cmd.Parameters.AddWithValue("@PointMincopy", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@PointMincopy", letterGrade.PointMincopy);
                }
                //DATETIME

                if (ReferenceEquals(letterGrade.createdTime, null) ||
                    (letterGrade.createdTime == DateTime.MinValue))
                {
                    cmd.Parameters.AddWithValue("@createdTime", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@createdTime", letterGrade.createdTime);
                }
                //TEXT

                if (ReferenceEquals(letterGrade.Notes, null))
                {
                    cmd.Parameters.AddWithValue("@Notes", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@Notes", letterGrade.Notes);
                }


                int rowsAffected = cmd.ExecuteNonQuery();

                return(rowsAffected);
            }
            finally
            {
                conn.Close();
            }
        }
예제 #12
0
 public StudentCourse(Course course, LetterGrade grade, Semester semester)
 {
     Course   = course;
     Grade    = grade;
     Semester = semester;
 }
 partial void OnBeforePut(LetterGrade lettergrade);
 partial void OnAfterGetById(LetterGrade LetterGrades, String letterGradeId);
예제 #15
0
        /// <summary>
        /// Returns a count of the numbers of rows affected by the insert
        /// </summary>
        /// <param name="person"></param>
        /// <param name="dataSource"></param>
        /// <param name="dbName"></param>
        /// <returns></returns>



        public int Insert(LetterGrade letterGrade)
        {
            SqlConnection conn = this.CreateSqlConnection();

            try
            {
                this.InitializeConnection(conn);
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = String.Format(@"INSERT INTO [{0}].[LetterGrade] (LetterGradeId, Name, PointMin, PointMincopy, createdTime, Notes)
                                    VALUES (@LetterGradeId, @Name, @PointMin, @PointMincopy, @createdTime, @Notes)", this.Schema);



                if (ReferenceEquals(letterGrade.LetterGradeId, null))
                {
                    cmd.Parameters.AddWithValue("@LetterGradeId", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@LetterGradeId", letterGrade.LetterGradeId);
                }


                if (ReferenceEquals(letterGrade.Name, null))
                {
                    cmd.Parameters.AddWithValue("@Name", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@Name", letterGrade.Name);
                }


                if (ReferenceEquals(letterGrade.PointMin, null))
                {
                    cmd.Parameters.AddWithValue("@PointMin", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@PointMin", letterGrade.PointMin);
                }


                if (ReferenceEquals(letterGrade.PointMincopy, null))
                {
                    cmd.Parameters.AddWithValue("@PointMincopy", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@PointMincopy", letterGrade.PointMincopy);
                }


                if (ReferenceEquals(letterGrade.createdTime, null) ||
                    (letterGrade.createdTime == DateTime.MinValue))
                {
                    cmd.Parameters.AddWithValue("@createdTime", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@createdTime", letterGrade.createdTime);
                }


                if (ReferenceEquals(letterGrade.Notes, null))
                {
                    cmd.Parameters.AddWithValue("@Notes", DBNull.Value);
                }

                else
                {
                    cmd.Parameters.AddWithValue("@Notes", letterGrade.Notes);
                }


                int rowsAffected = cmd.ExecuteNonQuery();

                return(rowsAffected);
            }
            finally
            {
                conn.Close();
            }
        }
 partial void OnAfterPut(LetterGrade lettergrade);
 partial void OnBeforeDelete(LetterGrade lettergrade);
예제 #18
0
        static void Main(string[] args)
        {   //Init the variables
            int    ISMGrade;
            string LetterGrade;

            //Asking user for input
            Console.WriteLine("Welcome to Grader!");
            Console.WriteLine("Please enter the grade percentage you think you will get in ISM 4300. No % sign");
            //Assigning the input to variables
            ISMGrade = int.Parse(Console.ReadLine());
            //Using conditional to assing letter grade to grade percentage.
            if (ISMGrade >= 98)
            {
                LetterGrade = "A+";
            }
            else if (ISMGrade >= 92 && ISMGrade <= 97)
            {
                LetterGrade = "A";
            }
            else if (ISMGrade >= 90 && ISMGrade <= 91)
            {
                LetterGrade = "A-";
            }
            else if (ISMGrade >= 88 && ISMGrade <= 89)
            {
                LetterGrade = "B+";
            }
            else if (ISMGrade >= 82 && ISMGrade <= 87)
            {
                LetterGrade = "B";
            }
            else if (ISMGrade >= 80 && ISMGrade <= 81)
            {
                LetterGrade = "B-";
            }
            else if (ISMGrade >= 78 && ISMGrade <= 79)
            {
                LetterGrade = "C+";
            }
            else if (ISMGrade >= 72 && ISMGrade <= 77)
            {
                LetterGrade = "C";
            }
            else if (ISMGrade >= 70 && ISMGrade <= 71)
            {
                LetterGrade = "C-";
            }
            else if (ISMGrade >= 68 && ISMGrade <= 69)
            {
                LetterGrade = "D+";
            }
            else if (ISMGrade >= 62 && ISMGrade <= 67)
            {
                LetterGrade = "D";
            }
            else if (ISMGrade >= 60 && ISMGrade <= 61)
            {
                LetterGrade = "D-";
            }
            else
            {
                LetterGrade = "F";
            }
            //Finally writing the letter grade that they will get based on the percentage the user input
            Console.WriteLine("The letter grade of that is " + LetterGrade.ToString());
        }
 partial void OnAfterDelete(LetterGrade lettergrade);
 internal static LetterGrade FromCsv(string line)
 {
     var parts = line.Split(",".ToCharArray());
     var rv = new LetterGrade();
     rv.Letter = parts[0];
     rv.Points = double.Parse(parts[1]);
     return rv;
 }
예제 #21
0
 public StudentCourse(Course course, LetterGrade grade)
 {
     Course = course;
     Grade  = grade;
 }