コード例 #1
0
        public GradesResult removeGrades(int id, byte[] currentTimeStamp)
        {
            using (var db = new NTR2013Entities())
            {
                var original = db.Grades.Find(id);
                if (original != null)
                {
                    //Console.WriteLine("sfasdfasdf stamp" + Convert.ToString(original.TimeStamp));
                    if (!compareTimeStamp(original.TimeStamp, currentTimeStamp))
                    {
                        GradesResult result = new GradesResult(ErrorMessage.REMOVE_GRADES_CONCURRENCY);
                        Grades       grade  = new Grades {
                            GradeID = original.GradeID, RealisationID = original.RealisationID, Name = original.Name, MaxValue = original.MaxValue, TimeStamp = original.TimeStamp, Realisations = null, GradeValues = null
                        };
                        result.data = grade;
                        return(result);
                    }

                    List <GradeValues> list           = db.GradeValues.ToList();
                    string             studentsToEdit = "";

                    foreach (GradeValues g in list)
                    {
                        if (g.GradeID == id)
                        {
                            //Value 10 pleaces
                            if (g.Value.Equals("          "))
                            {
                                db.GradeValues.Remove(g);
                            }
                            else
                            {
                                //sprawdzenie studentow z ocena
                                var originalRegistration = db.Registrations.Find(g.RegistrationID);
                                var originalStudent      = db.Students.Find(originalRegistration.StudentID);
                                studentsToEdit += originalStudent.FirstName + " " + originalStudent.LastName + ", ";
                            }
                        }
                    }

                    if (!studentsToEdit.Equals(""))
                    {
                        studentsToEdit = studentsToEdit.Substring(0, studentsToEdit.Length - 2);
                        return(new GradesResult(studentsToEdit));
                    }

                    db.Grades.Remove(original);
                    db.SaveChanges();
                    return(new GradesResult(original));
                }

                return(new GradesResult(ErrorMessage.REMOVE_GRADES_COULD_NOT_FIND_GRADES_ID));
            }
        }
コード例 #2
0
        //async Task<partialviewresult>
        //async Task<JsonResult>
        public ActionResult Create(int realizationId, string name, string maxValue)
        {
            //################### NO DB TESTS ###################
            //Grades g = new Grades { GradeID = 789, RealisationID = realizationId, Name = name, MaxValue = maxValue };
            //return Json(g);

            //GradesResult r = new GradesResult { msg = null, data = new Grades { GradeID = 898, RealisationID = realizationId, Name = name, MaxValue = maxValue } };
            //return Json(r);

            GradesAccess g = new GradesAccess();
            GradesResult r = g.addGrades(realizationId, name, maxValue);
            //return Json(r);
            GradesResult r2 = new GradesResult { msg = null, data = new Grades { GradeID = 898, RealisationID = realizationId, Name = name, MaxValue = maxValue, TimeStamp = new byte[8] } };
            return Json(r);
        }
コード例 #3
0
        public GradesResult removeGrades(int id, byte[] currentTimeStamp)
        {
            using (var db = new NTR2013Entities())
            {
                var original = db.Grades.Find(id);
                if (original != null)
                {
                    //Console.WriteLine("sfasdfasdf stamp" + Convert.ToString(original.TimeStamp));
                    if (!compareTimeStamp(original.TimeStamp, currentTimeStamp))
                    {
                        GradesResult result = new GradesResult(ErrorMessage.REMOVE_GRADES_CONCURRENCY);
                        Grades grade = new Grades { GradeID = original.GradeID, RealisationID = original.RealisationID, Name = original.Name, MaxValue = original.MaxValue, TimeStamp = original.TimeStamp, Realisations = null, GradeValues = null };
                        result.data = grade;
                        return result;
                    }

                    List<GradeValues> list = db.GradeValues.ToList();
                    string studentsToEdit = "";

                    foreach (GradeValues g in list)
                    {
                        if (g.GradeID == id)
                        {
                            //Value 10 pleaces
                            if (g.Value.Equals("          "))
                                db.GradeValues.Remove(g);
                            else
                            {
                                //sprawdzenie studentow z ocena
                                var originalRegistration = db.Registrations.Find(g.RegistrationID);
                                var originalStudent = db.Students.Find(originalRegistration.StudentID);
                                studentsToEdit += originalStudent.FirstName + " " + originalStudent.LastName + ", ";
                            }
                        }
                    }

                    if (!studentsToEdit.Equals(""))
                    {
                        studentsToEdit = studentsToEdit.Substring(0, studentsToEdit.Length - 2);
                        return new GradesResult(studentsToEdit);
                    }

                    db.Grades.Remove(original);
                    db.SaveChanges();
                    return new GradesResult(original);
                }

                return new GradesResult(ErrorMessage.REMOVE_GRADES_COULD_NOT_FIND_GRADES_ID);
            }
        }
コード例 #4
0
        public GradesResult editGrades(int gradeId, string name, string maxValue, byte[] currentTimeStamp)
        {
            using (var db = new NTR2013Entities())
            {
                var original = db.Grades.Find(gradeId);
                if (original != null)
                {
                    if (!compareTimeStamp(original.TimeStamp, currentTimeStamp))
                    {
                        GradesResult result = new GradesResult(ErrorMessage.REMOVE_GRADES_CONCURRENCY);
                        Grades g = new Grades { GradeID = original.GradeID, RealisationID = original.RealisationID, Name = original.Name, MaxValue = original.MaxValue, TimeStamp = original.TimeStamp, Realisations = null, GradeValues = null };
                        result.data = g;
                        return result;
                    }

                    List<Grades> list = getGrades(original.RealisationID);
                    foreach (Grades g in list)
                    {
                        if (g.Name.Equals(name))
                            return new GradesResult(ErrorMessage.EDIT_GRADES_NAME_EXISTS);
                    }

                    if (!original.MaxValue.Equals(maxValue))
                    {
                        List<GradeValues> l = db.GradeValues.ToList();
                        string studentsToEdit = "";

                        foreach (GradeValues g in l)
                        {
                            if (g.GradeID == original.GradeID)
                            {
                                //Value 10 pleaces
                                if (!g.Value.Equals("          "))
                                {
                                    //sprawdzenie studentow z ocena
                                    var originalRegistration = db.Registrations.Find(g.RegistrationID);
                                    var originalStudent = db.Students.Find(originalRegistration.StudentID);
                                    studentsToEdit += originalStudent.FirstName + " " + originalStudent.LastName + ", ";
                                }
                            }
                        }

                        if (!studentsToEdit.Equals(""))
                        {
                            studentsToEdit = studentsToEdit.Substring(0, studentsToEdit.Length - 2);
                            return new GradesResult(studentsToEdit);
                        }
                    }

                    original.Name = name;
                    original.MaxValue = maxValue;
                    //original.TimeStamp = null;
                    db.SaveChanges();

                    Grades grade = new Grades { GradeID = original.GradeID, RealisationID = original.RealisationID, Name = original.Name, MaxValue = original.MaxValue, TimeStamp = original.TimeStamp, Realisations = null, GradeValues = null };

                    return new GradesResult(grade);
                }

                return new GradesResult(ErrorMessage.EDIT_GRADES_COULD_NOT_FIND_GRADES_ID);
            }
        }
コード例 #5
0
        public GradesResult editGrades(int gradeId, string name, string maxValue, byte[] currentTimeStamp)
        {
            using (var db = new NTR2013Entities())
            {
                var original = db.Grades.Find(gradeId);
                if (original != null)
                {
                    if (!compareTimeStamp(original.TimeStamp, currentTimeStamp))
                    {
                        GradesResult result = new GradesResult(ErrorMessage.REMOVE_GRADES_CONCURRENCY);
                        Grades       g      = new Grades {
                            GradeID = original.GradeID, RealisationID = original.RealisationID, Name = original.Name, MaxValue = original.MaxValue, TimeStamp = original.TimeStamp, Realisations = null, GradeValues = null
                        };
                        result.data = g;
                        return(result);
                    }

                    List <Grades> list = getGrades(original.RealisationID);
                    foreach (Grades g in list)
                    {
                        if (g.Name.Equals(name))
                        {
                            return(new GradesResult(ErrorMessage.EDIT_GRADES_NAME_EXISTS));
                        }
                    }

                    if (!original.MaxValue.Equals(maxValue))
                    {
                        List <GradeValues> l = db.GradeValues.ToList();
                        string             studentsToEdit = "";

                        foreach (GradeValues g in l)
                        {
                            if (g.GradeID == original.GradeID)
                            {
                                //Value 10 pleaces
                                if (!g.Value.Equals("          "))
                                {
                                    //sprawdzenie studentow z ocena
                                    var originalRegistration = db.Registrations.Find(g.RegistrationID);
                                    var originalStudent      = db.Students.Find(originalRegistration.StudentID);
                                    studentsToEdit += originalStudent.FirstName + " " + originalStudent.LastName + ", ";
                                }
                            }
                        }

                        if (!studentsToEdit.Equals(""))
                        {
                            studentsToEdit = studentsToEdit.Substring(0, studentsToEdit.Length - 2);
                            return(new GradesResult(studentsToEdit));
                        }
                    }

                    original.Name     = name;
                    original.MaxValue = maxValue;
                    //original.TimeStamp = null;
                    db.SaveChanges();

                    Grades grade = new Grades {
                        GradeID = original.GradeID, RealisationID = original.RealisationID, Name = original.Name, MaxValue = original.MaxValue, TimeStamp = original.TimeStamp, Realisations = null, GradeValues = null
                    };


                    return(new GradesResult(grade));
                }

                return(new GradesResult(ErrorMessage.EDIT_GRADES_COULD_NOT_FIND_GRADES_ID));
            }
        }