Exemplo n.º 1
0
        public HttpStatusCodeResult Grade(GradingViewModel form)
        {
            var teacher = db.Teachers.Find(HttpContext.User.Identity.GetUserId <int>());
            var grading = db.Gradings.Add(new Grading
            {
                Grade      = form.grade,
                Date       = DateTime.Now,
                Feedback   = form.feedback,
                Teacher_Id = teacher.Id
            });

            db.SaveChanges();
            var sub  = db.Submissions.Find(form.sub_id);
            var name = sub.Student.User.FullName;

            sub.Grading_Id = grading.Id;
            db.SaveChanges();
            var msg = String.Format("Satte betyget ({0}) på '{1}'s inlämning", form.grade, name);

            return(new HttpStatusCodeResult(200, msg));
        }
        private GradingViewModel GetGradingById(int headerId)
        {
            var responseData = new GradingViewModel();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                var query = $"select Header_ID, Schedule_ID, Header_Name, Exam_ID from EvalForms_Headers where Header_ID = {headerId}";
                using (var da = new SqlDataAdapter(query, connection))
                {
                    var tblPromotion = new DataTable();
                    try
                    {
                        connection.Open();
                        da.Fill(tblPromotion);
                        if (tblPromotion.Rows.Count != 0)
                        {
                            for (var i = 0; i < tblPromotion.Rows.Count; i++)
                            {
                                var data = tblPromotion.Rows[i];

                                responseData = new GradingViewModel
                                {
                                    GradingId   = data.Field <int>("Header_ID"),
                                    GradingName = data.Field <string>("Header_Name"),
                                    ScheduleId  = data.Field <int>("Schedule_ID"),
                                    ExamId      = data.Field <int>("Exam_ID")
                                };
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
            }

            return(responseData);
        }