示例#1
0
        public JsonResult AddLessonToStudent(int lessonId, params int[] arrayOfStudentId)
        {
            if (arrayOfStudentId.Length == 0)
            {
                return(Json(false));
            }

            var lesson = _dbContex.Lessons
                         .Where(l => l.Id == lessonId)
                         .SingleOrDefault();

            foreach (int id in arrayOfStudentId)
            {
                var student = _dbContex.Students
                              .Where(s => s.Id == id)
                              .SingleOrDefault();
                StudentLessons studentLessons = new StudentLessons()
                {
                    Lesson  = lesson,
                    Student = student
                };
                _dbContex.Add(studentLessons);
            }
            bool flag = true ? _dbContex.SaveChanges() != 0 : false;

            return(Json(flag));
        }
示例#2
0
        private static void AddOrRemvoveFromGroup(Context context, List <int> studentIds, int lessonId)
        {
            // אםקיים שיעור נלווה - הבא
            var l = context.Lessons.Where(x => x.ParentId == lessonId).FirstOrDefault();

            if (l != null)
            {
                // כל התלמידים של השיעור
                var sl = context.StudentLessons.Where(x => x.Lesson_Id == l.Id).ToList();

                //if(sl.Count()!= studentIds.Count())
                //{
                // קיים במערכת ולא
                foreach (StudentLessons item in sl)
                {
                    int studentId = item.User_Id;

                    bool exists = studentIds.Contains(studentId);

                    if (!exists)
                    {
                        InsertIntoLog(item.Lesson_Id, 4, context, "הורדת תלמיד מקבוצה", item);

                        context.StudentLessons.Remove(item);
                    }
                }

                // איד חדש שלא קיים במערכת
                foreach (int itemStudId in studentIds)
                {
                    var studentInSystem = context.StudentLessons.Where(x => x.Lesson_Id == l.Id && x.User_Id == itemStudId).FirstOrDefault();
                    if (studentInSystem == null)
                    {
                        var slin = new StudentLessons()
                        {
                            Lesson_Id = l.Id, User_Id = itemStudId, Status = "", Details = "", IsComplete = 0, HorseId = null, OfficeDetails = ""
                        };
                        context.StudentLessons.Add(slin);
                        InsertIntoLog(l.Id, 3, context, "הוספת תלמיד לקבוצה", slin);
                    }
                }



                AddOrRemvoveFromGroup(context, studentIds, l.Id);
            }


            context.SaveChanges();
            // }
        }
 public IQueryable <StudentLessonEntity> GetAdditionalLessonsByGroup([NotNull] StudentEntity student, [NotNull] GroupEntity currentGroup)
 {
     if (student.Id == default)
     {
         return(new List <StudentLessonEntity>().AsQueryable());
     }
     return(StudentLessons
            .Where(studentLesson => studentLesson.Student.Id == student.Id)
            .Where(studentLesson => studentLesson.Lesson._GroupId != default
             ? currentGroup.Id != studentLesson.Lesson.Group.Id
             : studentLesson.Lesson.Stream.Groups.All(
                       group => currentGroup.Id != group.Id
                       )));
 }
        private void AddStudent(Applicant applicant)
        {
            Student student = new Student()
            {
                ApplicantId = applicant.Id,
                Description = applicant.Description
            };
            StudentLessons studentLessons = new StudentLessons()
            {
                Student = student,
                Lesson  = _dbContext.Lessons.Find(applicant.Lesson.Id),
            };

            _dbContext.Add(studentLessons);
        }
        public IQueryable <StudentLessonEntity> GetAllAdditionalLessons([NotNull] StudentEntity student)
        {
            if (student.Id == default)
            {
                return(new List <StudentLessonEntity>().AsQueryable());
            }
            var studentGroupsIds = student.Groups?.Select(group => group.Id).ToList() ?? new List <long>();

            return(StudentLessons
                   .Where(studentLesson => studentLesson.Student.Id == student.Id)
                   .Where(studentLesson => studentLesson.Lesson._GroupId != default
                    ? studentGroupsIds.All(studentGroupId => studentGroupId != studentLesson.Lesson.Group.Id)
                    : studentLesson.Lesson.Stream.Groups.All(
                              group => studentGroupsIds.All(studentGroupId => studentGroupId != group.Id)
                              )));
        }
示例#6
0
        private static void InsertIntoLog(int LessonId, int Type, Context context, string Details, StudentLessons sl = null)
        {
            var Lesson = context.Lessons.Where(x => x.Id == LessonId).FirstOrDefault();

            LogsLessons lg = new LogsLessons();

            lg.Type          = Type;
            lg.TimeStamp     = DateTime.Now;
            lg.LessonDate    = Lesson.Start;
            lg.LessonId      = LessonId;
            lg.Instructor_Id = Lesson.Instructor_Id;
            lg.Details       = Details;
            if (sl != null)
            {
                lg.StudentId = sl.User_Id;
                lg.Status    = sl.Status;
            }

            lg.UserId = UsersService.GetCurrentUser().Id;

            context.LogsLessons.Add(lg);
        }
示例#7
0
        private static void ReassignStudentLessons(JObject Lesson, DataModels.Context Context)
        {
            int LessonId = Lesson["id"].Value <int>();

            int onlyMultiple = 0;

            if (Lesson["onlyMultiple"] != null)
            {
                onlyMultiple = Lesson["onlyMultiple"].Value <int>();
            }


            var TempStudentLessonsList = Context.StudentLessons.Where(sl => sl.Lesson_Id == LessonId).ToList();



            var CurrentUserRole = UsersService.GetCurrentUser().Role;

            if (CurrentUserRole == "instructor")
            {
                Context.StudentLessons.RemoveRange(Context.StudentLessons.Where(sl => sl.Lesson_Id == LessonId && sl.Status != "completionReq" && sl.Status != "completionReqCharge"));
            }
            else
            {
                Context.StudentLessons.RemoveRange(Context.StudentLessons.Where(sl => sl.Lesson_Id == LessonId));
            }


            if (Lesson["students"] != null)
            {
                var StudentIds = Lesson["students"].Values <int>().ToList();
                foreach (var StudentId in StudentIds)
                {
                    var StatusData = GetStatusDataFromJson(Lesson, StudentId);

                    string Matarot = "", Mahalak = "", HearotStatus = "", Mashov = "";

                    var TempStudentLessons = TempStudentLessonsList.Where(x => x.User_Id == StudentId).FirstOrDefault();

                    if (TempStudentLessons != null)
                    {
                        Matarot      = TempStudentLessons.Matarot;
                        Mahalak      = TempStudentLessons.Mahalak;
                        HearotStatus = TempStudentLessons.HearotStatus;
                        Mashov       = TempStudentLessons.Mashov;
                    }



                    if ((StatusData[0] == "completionReq" || StatusData[0] == "completionReqCharge") && (StatusData[2] == "0" || StatusData[2] == null))
                    {
                        StatusData[2] = "1";
                    }



                    if (StatusData[0] == "completion" && StatusData[2] == "2")
                    {
                        StatusData[0] = "completion";
                        StatusData[2] = "5";

                        var conn            = Context.Database.Connection;
                        var connectionState = conn.State;
                        if (connectionState != ConnectionState.Open)
                        {
                            conn.Open();
                        }
                        using (var cmd = conn.CreateCommand())
                        {
                            cmd.CommandText = "   UPDATE StudentLessons SET IsComplete = 2 "
                                              + "  WHERE Lesson_Id = (SELECT top 1 Lesson_Id FROM StudentLessons WHERE Lesson_Id < " + LessonId + "  and User_Id = " + StudentId
                                              + "  and Status in('completionReq','completionReqCharge') and IsComplete = 1 order by Lesson_Id desc) and User_Id = " + StudentId;



                            cmd.ExecuteNonQuery();
                        }

                        conn.Close();
                    }


                    if ((StatusData[0] == "" || StatusData[0] == null || StatusData[0] == "completion") && (StatusData[2] == "3" || StatusData[2] == "4" || StatusData[2] == "5" || StatusData[2] == "6"))
                    {
                        StatusData[0] = "completion";
                        StatusData[2] = "5";
                    }


                    if ((StatusData[0] == "notAttended") && (StatusData[2] == "3" || StatusData[2] == "4" || StatusData[2] == "5" || StatusData[2] == "6"))
                    {
                        StatusData[0] = "completion";
                        StatusData[2] = "3";
                    }

                    if ((StatusData[0] == "attended") && (StatusData[2] == "3" || StatusData[2] == "4" || StatusData[2] == "5" || StatusData[2] == "6"))
                    {
                        StatusData[0] = "completion";
                        StatusData[2] = "4";
                    }

                    if ((StatusData[0] == "notAttendedCharge") && (StatusData[2] == "3" || StatusData[2] == "4" || StatusData[2] == "5" || StatusData[2] == "6"))
                    {
                        StatusData[0] = "completion";
                        StatusData[2] = "6";
                    }

                    if ((StatusData[0] != "completion") && (StatusData[0] != "completionReq") && (StatusData[0] != "completionReqCharge"))
                    {
                        StatusData[2] = "0";
                    }

                    StudentLessons sl = new StudentLessons()
                    {
                        Lesson_Id     = LessonId,
                        User_Id       = StudentId,
                        Status        = StatusData[0],
                        Details       = StatusData[1],
                        IsComplete    = Int32.Parse((StatusData[2] == null) ? "0" : StatusData[2]),
                        HorseId       = Int32.Parse((StatusData[3] == null) ? "0" : StatusData[3]),
                        OfficeDetails = StatusData[4],
                        Matarot       = Matarot,
                        Mahalak       = Mahalak,
                        HearotStatus  = HearotStatus,
                        Mashov        = Mashov
                    };
                    Context.StudentLessons.Add(sl);
                    InsertIntoLog(LessonId, 2, Context, " עדכון סטטוס  " + StatusData[2], sl);
                }


                Context.SaveChanges();

                // if (StudentIds.Count() > 1)

                if (onlyMultiple == 1)
                {
                    AddOrRemvoveFromGroup(Context, StudentIds, LessonId);
                }
            }
        }