Ejemplo n.º 1
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));
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 3
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));
            }
        }
Ejemplo n.º 4
0
        internal static void RemoveAllAttendance()
        {
            var db = new DnevnikEntities();

            db.Attendances.RemoveRange(db.Attendances.ToList());
            db.SaveChanges();
            db.Dispose();
        }
Ejemplo n.º 5
0
        internal static void DeleteAllGrades()
        {
            var db = new DnevnikEntities();

            db.Grades.RemoveRange(db.Grades.ToList());
            db.SaveChanges();
            db.Dispose();
        }
Ejemplo n.º 6
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();
     }
 }
Ejemplo n.º 7
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();
     }
 }
Ejemplo n.º 8
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();
     }
 }
Ejemplo n.º 9
0
 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();
     }
 }
Ejemplo n.º 10
0
        public static void DeleteAllStudents()
        {
            GradesRepository.DeleteAllGrades();
            AttendanceRepository.RemoveAllAttendance();

            var db = new DnevnikEntities();

            db.Students.RemoveRange(db.Students);
            db.SaveChanges();
            db.Dispose();
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
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
            });
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
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();
     }
 }
Ejemplo n.º 16
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));
            }
        }
Ejemplo n.º 17
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();
     }
 }
Ejemplo n.º 18
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();
            }
        }
Ejemplo n.º 19
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();
     }
 }
Ejemplo n.º 20
0
        public static void AddStudent(Student student, int class_id)
        {
            Student stud = new Student()
            {
                EGN      = student.EGN,
                Number   = student.Number,
                Name     = student.Name,
                Class_id = class_id
            };

            var db = new DnevnikEntities();

            db.Students.Add(stud);
            db.Entry(stud).State = EntityState.Added;
            db.SaveChanges();
            db.Dispose();
        }
Ejemplo n.º 21
0
        public static void SaveStudents(List <Student> students)
        {
            var db = new DnevnikEntities();

            foreach (var s in students)
            {
                db.Students.Attach(s);
                var entry = db.Entry(s);
                entry.Property(e => e.Number).IsModified = true;
                entry.Property(e => e.Name).IsModified   = true;
                entry.Property(e => e.Note).IsModified   = true;
                entry.Property(e => e.EGN).IsModified    = true;
            }

            db.SaveChanges();
            db.Dispose();
        }
Ejemplo n.º 22
0
        public static void DeleteStudent(int id, int class_id)
        {
            var db      = new DnevnikEntities();
            var student = db.Students.Where(s => s.Id == id && s.Class_id == class_id).FirstOrDefault();

            if (student == null)
            {
                throw new ArgumentException();
            }

            db.Grades.RemoveRange(db.Grades.Where(g => g.Student_id == id));
            db.Attendances.RemoveRange(db.Attendances.Where(a => a.Student_id == id).ToList());
            db.Students.Remove(student);
            //remove attendance records

            db.SaveChanges();
            db.Dispose();
        }
Ejemplo n.º 23
0
        public JsonResult addClass(string Name, string Level, string Teacher)
        {
            int lvl   = Int32.Parse(Level);
            int teach = Int32.Parse(Teacher);

            using (DnevnikEntities db = new DnevnikEntities())
            {
                Class d = new Class();
                d.Name    = Name;
                d.Level   = lvl;
                d.Teacher = teach;
                db.Classes.Add(d);
                db.SaveChanges();
                ModelState.Clear();

                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 24
0
        public JsonResult addSubject(string SubjectName, string Level)
        {
            int l = int.Parse(Level);

            using (DnevnikEntities db = new DnevnikEntities())
            {
                Subject d = new Subject();
                d.SubjectName = SubjectName;
                d.Level       = l;

                db.Subjects.Add(d);
                db.SaveChanges();
                ModelState.Clear();



                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 25
0
        public JsonResult editClass(string id, string Name, string Level, string Teacher)
        {
            int X     = Int32.Parse(id);
            int teach = Int32.Parse(Teacher);
            int lvl   = Int32.Parse(Level);

            using (DnevnikEntities db = new DnevnikEntities())
            {
                Class d = db.Classes.Find(X);
                d.Name            = Name;
                d.Level           = lvl;
                d.Teacher         = teach;
                db.Entry(d).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                ModelState.Clear();

                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 26
0
        public JsonResult addManager(string UserName, string Password, string LastName,
                                     string FirstName, string Address, string Phone, string Email)
        {
            using (DnevnikEntities db = new DnevnikEntities())
            {
                Director d = new Director();
                d.UserName  = UserName;
                d.Password  = Crypto.HashPassword(Password);
                d.LastName  = LastName;
                d.FirstName = FirstName;
                d.Address   = Address;
                d.Phone     = Phone;
                d.Email     = Email;
                db.Directors.Add(d);
                db.SaveChanges();
                ModelState.Clear();



                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 27
0
        public JsonResult editSubject(string id, string SubjectName, string Level)
        {
            int X     = Int32.Parse(id);
            int level = int.Parse(Level);

            using (DnevnikEntities db = new DnevnikEntities())
            {
                Subject d = new Subject();
                d = db.Subjects.Find(X);
                db.Subjects.Attach(d);
                d.SubjectName = SubjectName;
                d.Level       = level;
                db.Entry(d).Property(p => p.Level).IsModified       = true;
                db.Entry(d).Property(p => p.SubjectName).IsModified = true;
                db.SaveChanges();
                ModelState.Clear();



                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 28
0
        public ActionResult EditFirstTime(HttpPostedFileBase ImageFile, Director d, string pass, string passConf)
        {
            if (ModelState.IsValid)
            {
                if (pass == passConf)
                {
                    if (ImageFile != null)
                    {
                        string fileName      = Path.GetFileNameWithoutExtension(ImageFile.FileName);
                        string fileExtension = Path.GetExtension(ImageFile.FileName);
                        fileName    = fileName + DateTime.Now.ToString("yymmssfff") + fileExtension;
                        d.ImagePath = "~/image/directorPhoto/" + fileName;
                        fileName    = Path.Combine(Server.MapPath("~/image/directorPhoto/"), fileName);
                        ImageFile.SaveAs(fileName);
                    }
                    var db = new DnevnikEntities();
                    db.Directors.Attach(d);
                    d.Password = Crypto.HashPassword(pass);
                    db.Entry(d).Property(p => p.Password).IsModified  = true;
                    db.Entry(d).Property(p => p.LastName).IsModified  = true;
                    db.Entry(d).Property(p => p.FirstName).IsModified = true;
                    db.Entry(d).Property(p => p.DoB).IsModified       = true;
                    db.Entry(d).Property(p => p.Address).IsModified   = true;
                    db.Entry(d).Property(p => p.Phone).IsModified     = true;
                    db.Entry(d).Property(p => p.Email).IsModified     = true;
                    db.Entry(d).Property(p => p.ImagePath).IsModified = true;
                    db.SaveChanges();

                    return(RedirectToAction("Index", new { id = d.Id }));
                }
                else
                {
                    ViewBag.Pass = "******";
                    return(View());
                }
            }
            return(View());
        }
Ejemplo n.º 29
0
        public JsonResult addManyTeachers(string UserName, string Amount)
        {
            int    x     = Int32.Parse(Amount);
            string uName = "";

            using (DnevnikEntities db = new DnevnikEntities())
            {
                Teacher d = new Teacher();

                for (int i = 1; i <= x; i++)
                {
                    uName      = UserName + x.ToString();
                    d.UserName = uName;
                    d.Password = Crypto.HashPassword("12345");
                    d.RoleId   = 4;
                    db.Teachers.Add(d);
                    db.SaveChanges();
                    ModelState.Clear();
                }

                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 30
0
        public JsonResult addManyClasses(string Name, string Amount)
        {
            int lvl = Int32.Parse(Amount);


            using (DnevnikEntities db = new DnevnikEntities())
            {
                Class d = new Class();

                for (int i = 1; i <= lvl; i++)
                {
                    d.Name  = Name;
                    d.Level = i;
                    db.Classes.Add(d);
                    db.SaveChanges();
                    ModelState.Clear();
                }



                return(Json(d, JsonRequestBehavior.AllowGet));
            }
        }