コード例 #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));
            }
        }
コード例 #2
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();
     }
 }
コード例 #3
0
        public JsonResult editTeacherTimeTable(string id, string subjOrd, string subject, string classId)
        {
            if (Request.IsAjaxRequest())
            {
                int       tId  = int.Parse(id);
                int       sId  = int.Parse(subject);
                int       cId  = int.Parse(classId);
                int       sOrd = int.Parse(subjOrd);
                TimeTable tb   = new TimeTable();
                tb = db.TimeTables.Where(t => t.Teacher == tId && t.subjectOrder == sOrd).FirstOrDefault();
                if (sId == 0)
                {
                    tb.Class           = cId;
                    db.Entry(tb).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    ModelState.Clear();
                }
                else if (cId == 0)
                {
                    tb.Subject         = sId;
                    db.Entry(tb).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    ModelState.Clear();
                }
                else
                {
                    tb.Subject         = sId;
                    tb.Class           = cId;
                    db.Entry(tb).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    ModelState.Clear();
                }
                return(new JsonResult {
                    Data = "", JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }

            return(new JsonResult
            {
                Data = "error",
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #4
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();
        }
コード例 #5
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();
        }
コード例 #6
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();
        }
コード例 #7
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));
            }
        }
コード例 #8
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();
     }
 }
コード例 #9
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));
            }
        }
コード例 #10
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();
     }
 }
コード例 #11
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();
            }
        }
コード例 #12
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();
     }
 }
コード例 #13
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();
        }
コード例 #14
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();
        }
コード例 #15
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));
            }
        }
コード例 #16
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());
        }
コード例 #17
0
        public static void AddGradesToDB(List <StudentGradesViewModel> students, int semester, int subject_id)
        {
            var db = new DnevnikEntities();

            try
            {
                //5 meseca za srok + 1 za srochna ocenka
                //ako e vtori semester + 1 za godishna ocenka
                int len = 0;
                if (semester == 1)
                {
                    len = 6;
                }
                else
                {
                    len = 7;
                }

                //za vseki uchenik vzemame ocenkite po mesec, razbivame gi i gi vkarvame v bazata
                foreach (var s in students)
                {
                    for (int i = 0; i < len; i++)
                    {
                        if (s.Grades[i] != string.Empty)
                        {
                            var grades = s.Grades[i].Split(new char[] { ',', ';' });//remove empty entries
                            foreach (var grade in grades)
                            {
                                if (grade.Trim() == string.Empty)
                                {
                                    continue;
                                }

                                int month = ConvertMonth(i, semester);

                                Grade g = new Grade
                                {
                                    Grade_month = month,
                                    Grade1      = System.Int32.Parse(grade.Trim()),
                                    Student_id  = s.Id,
                                    Subject_id  = subject_id,
                                };

                                db.Grades.Add(g);
                                db.Entry(g).State = EntityState.Added;
                            }
                        }
                    }
                }

                //iztrivame starite ocenki predi da vkarame novite
                foreach (var stud in students)
                {
                    GradesRepository.DeleteGradesBySubject(semester, stud.Id, subject_id);
                }

                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new ArgumentException();
            }
            finally
            {
                db.Dispose();
            }
        }
コード例 #18
0
        public static void UpdateAttendance(PeriodAttendance[] periods, DateTime date, int class_id)
        {
            using (var db = new DnevnikEntities())
            {
                var students = db.Students.Where(s => s.Class_id == class_id).ToList();
                foreach (var period in periods)
                {
                    string   izvineni = period.Izvineni;
                    string[] izvineniArr;
                    if (izvineni != null)
                    {
                        izvineniArr = izvineni.Split(new char[] { ',', ';' });
                    }
                    else
                    {
                        izvineniArr = new string[] { "" }
                    };

                    string   neizvineni = period.Neizvineni;
                    string[] neizvineniArr;
                    if (neizvineni != null)
                    {
                        neizvineniArr = neizvineni.Split(new char[] { ',', ';' });
                    }
                    else
                    {
                        neizvineniArr = new string[] { "" }
                    };

                    string   zakusneniq = period.Zakusneniq;
                    string[] zakusneniqArr;
                    if (zakusneniq != null)
                    {
                        zakusneniqArr = zakusneniq.Split(new char[] { ',', ';' });
                    }
                    else
                    {
                        zakusneniqArr = new string[] { "" }
                    };

                    for (int i = 0; i < 3; i++)
                    {
                        string[] process = null;

                        if (i == 0)
                        {
                            process = neizvineniArr;
                        }
                        else if (i == 1)
                        {
                            process = zakusneniqArr;
                        }
                        else
                        {
                            process = izvineniArr;
                        }

                        foreach (var item in process)
                        {
                            var     num     = item.Trim();
                            Student student = null;
                            if (num != String.Empty)
                            {
                                student = students.Where(s => s.Number == Int32.Parse(num)).FirstOrDefault();
                            }
                            if (student != null)
                            {
                                var att = new Attendance()
                                {
                                    Att_type   = i,
                                    Date1      = date,
                                    Period     = period.PeriodId,
                                    Student_id = student.Id
                                };
                                db.Attendances.Add(att);
                                db.Entry(att).State = EntityState.Added;
                            }
                        }
                    }
                }
                DeleteOldAttendance(date, class_id);
                db.SaveChanges();
            }
        }