Example #1
0
        public JsonResult addManyParents(string UserName, string Amount, string ClassId)
        {
            int    x     = Int32.Parse(Amount);
            string uName = "";
            int    y     = Int32.Parse(ClassId);

            using (DnevnikEntities db = new DnevnikEntities())
            {
                Parent d = new Parent();
                Pupil  p = new Pupil();

                for (int i = 1; i <= x; i++)
                {
                    uName      = UserName + i.ToString();
                    d.UserName = uName;
                    d.Password = Crypto.HashPassword("1111");
                    d.RoleId   = 5;

                    p.Username = uName + "child";
                    p.Parent   = d.Id;
                    p.Class    = y;
                    p.RoleId   = 6;
                    p.Password = Crypto.HashPassword("1111");

                    db.Pupils.Add(p);
                    db.Parents.Add(d);
                    db.SaveChanges();
                    ModelState.Clear();
                }

                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        public static void DeleteGradesBySubject(int semester, int student_id, int subject_id)
        {
            List <int> f = new List <int>()
            {
                9, 10, 11, 12, 1, 21
            };
            List <int> s = new List <int>()
            {
                2, 3, 4, 5, 6, 22, 23
            };
            List <int> toCheck = new List <int>();

            if (semester == 1)
            {
                toCheck = f;
            }
            else
            {
                toCheck = s;
            }

            using (var db = new DnevnikEntities())
            {
                //db.Database.ExecuteSqlCommand("DELETE FROM Grades WHERE Subject_id = @subject_id AND Student_id = @student_id",
                //    new SqlParameter("@subject_id", subject_id),
                //    new SqlParameter("@student_id", student_id));
                db.Grades.RemoveRange(db.Grades
                                      .Where(x =>
                                             toCheck.Contains(x.Grade_month) &&
                                             x.Subject_id == subject_id &&
                                             x.Student_id == student_id));
                db.SaveChanges();
            }
        }
Example #3
0
 public static void DeleteOldSchedule(int class_id, int semester)
 {
     using (var db = new DnevnikEntities())
     {
         db.Database.ExecuteSqlCommand("DELETE FROM Schedule WHERE Class_id = @id AND Semester = @semester", new SqlParameter("@id", class_id), new SqlParameter("@semester", semester));
     }
 }
Example #4
0
        public JsonResult editParent(string id, string UserName, string Password, string LastName,
                                     string FirstName, string Address, string Phone, string Email)
        {
            int X = Int32.Parse(id);

            using (DnevnikEntities db = new DnevnikEntities())
            {
                Parent d = db.Parents.Find(X);
                d.UserName        = UserName;
                d.Password        = Crypto.HashPassword(Password);
                d.LastName        = LastName;
                d.FirstName       = FirstName;
                d.Address         = Address;
                d.Phone           = Phone;
                d.Email           = Email;
                d.RoleId          = 5;
                db.Entry(d).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                ModelState.Clear();



                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }
Example #5
0
 public static void DeleteTeacher(int id)
 {
     using (var db = new DnevnikEntities())
     {
         db.Teachers.Remove(db.Teachers.Where(t => t.Id == id).FirstOrDefault());
         db.SaveChanges();
     }
 }
 public static List <Attendance> GetAttendanceBetweenDates(DateTime d1, DateTime d2, int class_id)
 {
     using (var db = new DnevnikEntities())
     {
         var att = db.Attendances.Where(a => a.Date1 >= d1 && a.Date1 <= d2 && a.Student.Class_id == class_id).ToList();
         return(att);
     }
 }
Example #7
0
        public static List <Teacher> GetTeachers()
        {
            var db       = new DnevnikEntities();
            var teachers = db.Teachers.Where(t => t.IsAdmin == 0).ToList();

            db.Dispose();
            return(teachers);
        }
        internal static void RemoveAllAttendance()
        {
            var db = new DnevnikEntities();

            db.Attendances.RemoveRange(db.Attendances.ToList());
            db.SaveChanges();
            db.Dispose();
        }
Example #9
0
        //private static

        public static int GetAllStudentsCount(int class_id)
        {
            DnevnikEntities db       = new DnevnikEntities();
            var             students = db.Students.Where(s => s.Class_id == class_id).Count();

            db.Dispose();
            return(students);
        }
Example #10
0
        internal static void DeleteAllGrades()
        {
            var db = new DnevnikEntities();

            db.Grades.RemoveRange(db.Grades.ToList());
            db.SaveChanges();
            db.Dispose();
        }
Example #11
0
        public static List <Subject> GetAllSubjects()
        {
            var db       = new DnevnikEntities();
            var subjects = db.Subjects.Where(s => s.Id > 1).ToList();

            db.Dispose();
            return(subjects);
        }
Example #12
0
        public static List <Student> GetAllStudents(int class_id)
        {
            var db       = new DnevnikEntities();
            var students = db.Students.Include("Grades").Include("Class").Include("Attendances").Where(s => s.Class_id == class_id).OrderBy(s => s.Number).ToList();

            db.Dispose();
            return(students);
        }
Example #13
0
 public static void DeleteSubject(int id)
 {
     using (var db = new DnevnikEntities())
     {
         db.Schedules.RemoveRange(db.Schedules.Where(s => s.Subject_id == id));
         db.Grades.RemoveRange(db.Grades.Where(g => g.Subject_id == id));
         db.Subjects.Remove(db.Subjects.Where(s => s.Id == id).FirstOrDefault());
         db.SaveChanges();
     }
 }
Example #14
0
        public static List <Class> GetClasses()
        {
            var db      = new DnevnikEntities();
            var classes = db.Classes.Include("Teachers").Where(c => c.Id > 1)
                          .OrderBy(c => c.Number)
                          .ThenBy(c => c.Letter).ToList();

            db.Dispose();
            return(classes);
        }
Example #15
0
 public static void AddClass(Class c)
 {
     using (var db = new DnevnikEntities())
     {
         db.Classes.Add(c);
         var entry = db.Entry(c);
         entry.State = EntityState.Added;
         db.SaveChanges();
     }
 }
 public static void DeleteOldAttendance(DateTime date, int class_id)
 {
     using (var db = new DnevnikEntities())
     {
         db.Attendances
         .RemoveRange(db.Attendances
                      .Where(a => a.Student.Class_id == class_id && a.Date1 == date)
                      .ToList());
         db.SaveChanges();
     }
 }
Example #17
0
        public static void DeleteAllStudents()
        {
            GradesRepository.DeleteAllGrades();
            AttendanceRepository.RemoveAllAttendance();

            var db = new DnevnikEntities();

            db.Students.RemoveRange(db.Students);
            db.SaveChanges();
            db.Dispose();
        }
Example #18
0
        public static void AddNewSchedule(List <Schedule> periods)
        {
            var db = new DnevnikEntities();

            foreach (var p in periods)
            {
                db.Schedules.Add(p);
                db.Entry(p).State = EntityState.Added;
            }
            db.SaveChanges();
            db.Dispose();
        }
Example #19
0
        public JsonResult addDiary(string tId, string dDate, string sId, string hTS, string dTS, string mark, string subject)
        {
            int     teacher    = Int32.Parse(tId);
            int     student    = int.Parse(sId);
            decimal Mark       = 0;
            string  attendance = " ";
            int     Subject    = int.Parse(subject);

            if (mark == "-")
            {
                attendance = "-";
            }
            else
            {
                Mark       = decimal.Parse(mark);
                attendance = "+";
            }
            DateTime?DDate = DateTime.Parse(dDate);

            if (Request.IsAjaxRequest())
            {
                DnevnikEntities db    = new DnevnikEntities();
                var             diary = ifExists(DDate, student, Subject);
                if (diary == null)
                {
                    Diary tt = new Diary();
                    tt.Attandance  = attendance;
                    tt.DateOfIssue = DDate;
                    tt.Details     = dTS;
                    tt.Homework    = hTS;
                    tt.Mark        = Mark;
                    tt.Pupil       = student;
                    tt.Subject     = Subject;
                    db.Diaries.Add(tt);
                    db.SaveChanges();
                    return(new JsonResult {
                        Data = "success", JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
                else
                {
                    return(new JsonResult {
                        Data = "exists", JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }

            return(new JsonResult
            {
                Data = "error",
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #20
0
        public static void AddTeacher(Teacher t)
        {
            t.Class_id = 1;
            var db = new DnevnikEntities();

            db.Teachers.Add(t);
            var entry = db.Entry(t);

            entry.State = EntityState.Added;
            db.SaveChanges();
            db.Dispose();
        }
Example #21
0
        public static void ImportStudents(List <Student> students)
        {
            var db = new DnevnikEntities();

            foreach (var stud in students)
            {
                db.Students.Add(stud);
                db.Entry(stud).State = EntityState.Added;
            }
            db.SaveChanges();
            db.Dispose();
        }
Example #22
0
        public static Student GetStudent(string egn)
        {
            var dbContext = new DnevnikEntities();
            var student   = dbContext
                            .Students
                            .Include("Grades")
                            .Include("Attendances")
                            .Where(s => s.EGN == egn)
                            .FirstOrDefault();

            dbContext.Dispose();
            return(student);
        }
Example #23
0
        public static List <Schedule> GetSchedule(int semester, int class_id)
        {
            var db       = new DnevnikEntities();
            var schedule = db.Schedules
                           .Include("Subject")
                           .Where(s => s.Class_id == class_id && s.Semester == semester)
                           .OrderBy(s => s.Day)
                           .ThenBy(s => s.Period)
                           .ToList();

            db.Dispose();
            return(schedule);
        }
        public static List <Attendance> GetAttendance(DateTime date, int class_id)
        {
            var db         = new DnevnikEntities();
            var attendance = db.Attendances
                             .Include("Student")
                             .Where(a => a.Date1 == date && a.Student.Class_id == class_id)
                             .OrderBy(a => a.Period)
                             .ThenBy(a => a.Student.Number)
                             .ToList();

            db.Dispose();
            return(attendance);
        }
Example #25
0
 public static void UpdateClasses(List <Class> c)
 {
     using (var db = new DnevnikEntities())
     {
         foreach (var item in c)
         {
             db.Classes.Add(item);
             var entry = db.Entry(item);
             entry.State = EntityState.Modified;
         }
         db.SaveChanges();
     }
 }
Example #26
0
        public JsonResult deleteClass(string id)
        {
            int X = Int32.Parse(id);

            using (DnevnikEntities db = new DnevnikEntities())
            {
                Class d = db.Classes.Find(X);
                db.Entry(d).State = System.Data.Entity.EntityState.Deleted;
                db.SaveChanges();
                ModelState.Clear();

                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }
Example #27
0
 public static void UpdateTeachers(List <Teacher> teachers)
 {
     using (var db = new DnevnikEntities())
     {
         foreach (var item in teachers)
         {
             db.Teachers.Add(item);
             var entry = db.Entry(item);
             entry.State = EntityState.Modified;
             entry.Property(e => e.IsAdmin).IsModified = false;
         }
         db.SaveChanges();
     }
 }
Example #28
0
        public static void AddSubject(string title, bool isZip)
        {
            using (var db = new DnevnikEntities())
            {
                Subject s = new Subject()
                {
                    Title = title,
                    IsZip = isZip
                };

                db.Subjects.Add(s);
                var entry = db.Entry(s);
                entry.State = EntityState.Added;
                db.SaveChanges();
            }
        }
Example #29
0
 public static void UpdateSubjects(List <Subject> subjects)
 {
     using (var db = new DnevnikEntities())
     {
         foreach (var sub in subjects)
         {
             if (sub.Title != null && sub.Title != String.Empty)
             {
                 db.Subjects.Add(sub);
                 var entry = db.Entry(sub);
                 entry.State = EntityState.Modified;
             }
         }
         db.SaveChanges();
     }
 }
Example #30
0
        public ActionResult EditFirstTime(int id)
        {
            DnevnikEntities _db          = new DnevnikEntities();
            string          directorName = HttpContext.User.Identity.Name;
            int             directorId   = _db.Directors.Where(p => (p.Email.Equals(directorName)) || (p.UserName.Equals(directorName))).FirstOrDefault().Id;

            if (id == directorId)
            {
                Director d = _db.Directors.Find(id);
                return(View(d));
            }



            return(View());
        }