示例#1
0
        public async Task <IActionResult> DeleteClassRoomStudent([FromBody] ClassRoomDetailsVM model)
        {
            await Task.Delay(5).ConfigureAwait(false);

            string TempStudentAsignList = string.Empty;
            string TempStudentKey       = string.Format("{0}_{1}", model.TempClassRefId, "ClassStudent");

            if (TempData.ContainsKey(TempStudentKey))
            {
                TempStudentAsignList = TempData[TempStudentKey].ToString();
            }
            else
            {
                if (model.AsignStudent != null)
                {
                    TempStudentAsignList = String.Join(",", model.AsignStudent);
                }
            }
            if (TempStudentAsignList.Contains(model.AutoCompleteSearchText))
            {
                var tempRegNos = TempStudentAsignList.Split(',');
                var listRegNos = new List <string>(tempRegNos);
                listRegNos.Remove(model.AutoCompleteSearchText);
                tempRegNos           = listRegNos.ToArray();
                TempStudentAsignList = String.Join(",", tempRegNos);
            }

            TempData[TempStudentKey] = TempStudentAsignList;
            model.AsignStudent       = TempStudentAsignList.Split(',');
            return(PartialView("_PartialClassRoomStudent", model.AsignStudentInfo));
        }
示例#2
0
        public async Task <IActionResult> AddClassRoomStudent([FromBody] ClassRoomDetailsVM model)
        {
            await Task.Delay(5).ConfigureAwait(false);

            string TempStudentAsignList = string.Empty;
            string TempStudentKey       = string.Format("{0}_{1}", model.TempClassRefId, "ClassStudent");

            if (TempData.ContainsKey(TempStudentKey))
            {
                TempStudentAsignList = TempData[TempStudentKey].ToString();
            }
            else
            {
                if (model.AsignStudent != null)
                {
                    TempStudentAsignList = String.Join(",", model.AsignStudent);
                }
            }
            string pattern = @"(?<=\[)(.*?)(?=\])";
            Match  output  = Regex.Match(model.AutoCompleteSearchText, pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase);

            if (output.Success)
            {
                if (!TempStudentAsignList.Contains(output.Value))
                {
                    TempStudentAsignList = TempStudentAsignList + "," + output.Value;
                }
            }
            TempData[TempStudentKey] = TempStudentAsignList;
            model.AsignStudent       = TempStudentAsignList.Split(',');
            return(PartialView("_PartialClassRoomStudent", model.AsignStudentInfo));
        }
示例#3
0
        public async Task <JsonResult> ClassRoom(ClassRoomDetailsVM model)
        {
            if (ModelState.IsValid)
            {
                string         TempMemberAsignList = string.Empty;
                CommonResponce result       = null;
                string         TempAsignKey = string.Format("{0}_{1}", model.TempClassRefId, "ClassTeacher");

                model.AllTeachers = await _ClassroomService.GetAllClassMembers(500, "teacher").ConfigureAwait(false);

                model.AllStudents = await _ClassroomService.GetAllClassMembers(500, "student").ConfigureAwait(false);

                if (TempData.ContainsKey(TempAsignKey))
                {
                    TempMemberAsignList = TempData[TempAsignKey].ToString();
                    model.AsignTeacher  = TempMemberAsignList.Split(',');
                }
                TempAsignKey = string.Format("{0}_{1}", model.TempClassRefId, "ClassStudent");
                if (TempData.ContainsKey(TempAsignKey))
                {
                    TempMemberAsignList = TempData[TempAsignKey].ToString();
                    model.AsignStudent  = TempMemberAsignList.Split(',');
                }

                // write the class save service
                if (model.Id > 0)
                {
                    // write update logic
                    result = await _ClassroomService.Update(model);
                }
                else
                {
                    // write save logic
                    result = await _ClassroomService.Insert(model);
                }

                return(Json(new { stat = result.Stat, msg = result.StatusMsg }));
            }
            else
            {
                return(Json(new { stat = false, msg = "Invalid Classroom data" }));
            }
        }
示例#4
0
        public async Task <IActionResult> ClassRoom(int id = 0)
        {
            CreateBreadCrumb(new[] { new { Name = "Home", ActionUrl = "#" },
                                     new { Name = "Classroom", ActionUrl = "/Classroom/Classroom" } });

            BaseViewModel VModel = null;

            var TempVModel = new ClassRoomDetailsVM();

            TempVModel.Id          = id;
            TempVModel.ApprootPath = GetBaseService().GetAppRootPath();
            //set class ref id and remove tempdata if exist
            var tempLoginUser = GetLoginUserInfo();

            if (tempLoginUser != null)
            {
                TempVModel.TempClassRefId = tempLoginUser.UserID;
            }

            string TempTeacherKey = string.Format("{0}_{1}", TempVModel.TempClassRefId, "ClassTeacher");

            if (TempData.ContainsKey(TempTeacherKey))
            {
                TempData.Remove(TempTeacherKey);
            }

            TempTeacherKey = string.Format("{0}_{1}", TempVModel.TempClassRefId, "ClassStudent");
            if (TempData.ContainsKey(TempTeacherKey))
            {
                TempData.Remove(TempTeacherKey);
            }
            //end of class ref id and remove tempdata if exist
            ////get value from service layer
            await _ClassroomService.GetClassroomVM(TempVModel);

            // end of service lyer

            VModel = await GetViewModel(TempVModel);

            return(View(VModel));
        }
示例#5
0
        public async Task <CommonResponce> Update(ClassRoomDetailsVM model)
        {
            CommonResponce result = new CommonResponce();

            try
            {
                result.StatusMsg = await _DBClassroomRepository.Update(model);

                if (result.StatusMsg.Equals("SUCCESS"))
                {
                    result.Stat      = true;
                    result.StatusMsg = "Successfully update Classroom";
                }
                else
                {
                    result.Stat = false;
                }
            }
            catch (Exception ex) { result.Stat = false; result.StatusMsg = ex.Message + " Failed to update Classroom"; }
            return(result);
        }
示例#6
0
        public async Task <string> Update(ClassRoomDetailsVM entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            string RtnFlag  = string.Empty;
            int    result   = 0;
            var    strategy = _DBContext.Database.CreateExecutionStrategy();
            await strategy.ExecuteAsync(async() =>
            {
                using (IDbContextTransaction transaction = _DBContext.Database.BeginTransaction())
                {
                    try
                    {
                        Tblmclassroom DBClassroom = await _DBContext.Tblmclassroom.Where(c => c.Id.Equals(entity.Id)).FirstOrDefaultAsync();
                        if (DBClassroom == null)
                        {
                            throw new Exception("Invalid Classroom data.");
                        }


                        DBClassroom.RefId       = entity.RefId;
                        DBClassroom.Description = entity.Description;
                        DBClassroom.Name        = entity.Name;
                        DBClassroom.SubjectId   = entity.SubjectId;
                        DBClassroom.StandardId  = entity.StandardId;
                        DBClassroom.ClassActivationThreshold = entity.ClassActivationThreshold;
                        DBClassroom.Scheduler = entity.Scheduler.ToJSONString();

                        ClassRoomEntities.Attach(DBClassroom);
                        _DBContext.Entry(DBClassroom).State = EntityState.Modified;

                        List <Tblrteacherclassroom> AllClassroomTeachers = await _DBContext.Tblrteacherclassroom.Where(c => c.ClassRoomId.Equals(entity.Id)).ToListAsync();
                        if (AllClassroomTeachers != null && AllClassroomTeachers.Count > 0)
                        {
                            _DBContext.Tblrteacherclassroom.RemoveRange(AllClassroomTeachers);
                            //foreach (var itemTeacher in AllClassroomTeachers)
                            //{
                            //    Tblrteacherclassroom DBClassTeacher = new Tblrteacherclassroom
                            //    {
                            //        Id = itemTeacher.Id,
                            //        TeacherId = itemTeacher.TeacherId,
                            //        ClassRoomId = itemTeacher.ClassRoomId,
                            //        CreatedOn = itemTeacher.CreatedOn
                            //    };
                            //    //ClassTeacherEntities.Remove(DBClassTeacher);
                            //    _DBContext.Entry(DBClassTeacher).State = EntityState.Deleted;
                            //}
                            //result = await _DBContext.SaveChangesAsync();
                        }
                        foreach (var itemTeacher in entity.AsignTeacherInfo)
                        {
                            Tblrteacherclassroom DBClassTeacher = new Tblrteacherclassroom
                            {
                                TeacherId   = itemTeacher.Id,
                                ClassRoomId = DBClassroom.Id,
                                CreatedOn   = DateTime.Now
                            };
                            ClassTeacherEntities.Add(DBClassTeacher);
                        }

                        List <Tblrstudentclassroom> AllClassroomStudents = await _DBContext.Tblrstudentclassroom.Where(c => c.ClassRoomId.Equals(entity.Id)).ToListAsync();
                        if (AllClassroomStudents != null && AllClassroomStudents.Count > 0)
                        {
                            _DBContext.Tblrstudentclassroom.RemoveRange(AllClassroomStudents);
                            //foreach (var itemStudent in AllClassroomStudents)
                            //{
                            //    Tblrstudentclassroom DBClassStudent = new Tblrstudentclassroom
                            //    {
                            //        Id = itemStudent.Id,
                            //        StudentId = itemStudent.StudentId,
                            //        ClassRoomId = itemStudent.ClassRoomId,
                            //        CreatedOn = itemStudent.CreatedOn
                            //    };
                            //    //ClassStudentEntities.Remove(DBClassStudent);
                            //    _DBContext.Entry(DBClassStudent).State = EntityState.Deleted;
                            //}
                            //result = await _DBContext.SaveChangesAsync();
                        }
                        foreach (var itemStudent in entity.AsignStudentInfo)
                        {
                            Tblrstudentclassroom DBClassStudent = new Tblrstudentclassroom
                            {
                                StudentId   = itemStudent.Id,
                                ClassRoomId = DBClassroom.Id,
                                CreatedOn   = DateTime.Now
                            };
                            ClassStudentEntities.Add(DBClassStudent);
                        }

                        result = await _DBContext.SaveChangesAsync();

                        transaction.Commit();
                        RtnFlag = "SUCCESS";
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        RtnFlag = ex.Message;
                    }
                }
            });

            return(RtnFlag);
        }
示例#7
0
        public async Task <string> Insert(ClassRoomDetailsVM entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            string RtnFlag  = string.Empty;
            var    strategy = _DBContext.Database.CreateExecutionStrategy();
            await strategy.ExecuteAsync(async() =>
            {
                using (IDbContextTransaction transaction = _DBContext.Database.BeginTransaction())
                {
                    try
                    {
                        Tblmclassroom DBClassroom = new Tblmclassroom
                        {
                            Id          = entity.Id,
                            RefId       = entity.RefId,
                            Description = entity.Description,
                            Name        = entity.Name,
                            SubjectId   = entity.SubjectId,
                            StandardId  = entity.StandardId,
                            ClassActivationThreshold = entity.ClassActivationThreshold,
                            Scheduler = entity.Scheduler.ToJSONString(),
                            CreatedBy = entity.BUserID,
                            CreatedOn = DateTime.Now
                        };
                        ClassRoomEntities.Add(DBClassroom);
                        int result = await _DBContext.SaveChangesAsync();

                        if (result > 0)
                        {
                            foreach (var itemTeacher in entity.AsignTeacherInfo)
                            {
                                Tblrteacherclassroom DBClassTeacher = new Tblrteacherclassroom
                                {
                                    TeacherId   = itemTeacher.Id,
                                    ClassRoomId = DBClassroom.Id,
                                    CreatedOn   = DateTime.Now
                                };
                                ClassTeacherEntities.Add(DBClassTeacher);
                            }

                            foreach (var itemStudent in entity.AsignStudentInfo)
                            {
                                Tblrstudentclassroom DBClassStudent = new Tblrstudentclassroom
                                {
                                    StudentId   = itemStudent.Id,
                                    ClassRoomId = DBClassroom.Id,
                                    CreatedOn   = DateTime.Now
                                };
                                ClassStudentEntities.Add(DBClassStudent);
                            }
                            result = await _DBContext.SaveChangesAsync();
                        }
                        else
                        {
                            throw new Exception("Fail to save classroom details");
                        }

                        transaction.Commit();
                        RtnFlag = "SUCCESS";
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        RtnFlag = ex.Message;
                        //throw;
                    }
                }
            });

            return(RtnFlag);
        }
示例#8
0
        public async Task <CommonResponce> GetClassroomVM(ClassRoomDetailsVM TempVModel)
        {
            bool isValid = true;

            TempVModel.Subjects = new List <AppSelectListItem>();
            var oSubject = await _DBSubjectRepository.GetAllSubjects(500).ConfigureAwait(false);

            if (oSubject != null && oSubject.Count > 0)
            {
                foreach (var item in oSubject)
                {
                    AppSelectListItem AppSItem = new AppSelectListItem {
                        Value = item.Id.ToString(), Text = item.Name
                    };
                    TempVModel.Subjects.Add(AppSItem);
                }
                ;
            }
            TempVModel.Standards = new List <AppSelectListItem>();
            var oStandards = await _DBStandardMasterRepository.GetAllStandards(500).ConfigureAwait(false);

            if (oStandards != null && oStandards.Count > 0)
            {
                foreach (var item in oStandards)
                {
                    AppSelectListItem AppSItem = new AppSelectListItem {
                        Value = item.Id.ToString(), Text = item.Name
                    };
                    TempVModel.Standards.Add(AppSItem);
                }
            }

            TempVModel.AllTeachers = await GetAllClassMembers(500, "teacher").ConfigureAwait(false); // new List<ClassMemberInfo>();

            TempVModel.AllStudents = await GetAllClassMembers(500, "student").ConfigureAwait(false); // new List<ClassMemberInfo>();

            if (TempVModel.Id > 0)
            {
                var oAssignTeachers = await _DBTeacherRepository.GetClassRoomTeachers(TempVModel.Id).ConfigureAwait(false);

                if (oAssignTeachers != null && oAssignTeachers.Count > 0)
                {
                    TempVModel.AsignTeacher = oAssignTeachers.Select(s => s.RegNo).ToArray();
                }

                var oAssignStudents = await _DBStudentRepository.GetClassRoomStudents(TempVModel.Id).ConfigureAwait(false);

                if (oAssignStudents != null && oAssignStudents.Count > 0)
                {
                    TempVModel.AsignStudent = oAssignStudents.Select(s => s.RegNo).ToArray();
                }

                var TempClassRoom = await _DBClassroomRepository.GetClassroomByClassroomId(TempVModel.Id);

                if (TempClassRoom != null)
                {
                    TempVModel.Description = TempClassRoom.Description;
                    TempVModel.RefId       = TempClassRoom.RefId;
                    TempVModel.Name        = TempClassRoom.Name;
                    TempVModel.SubjectId   = TempClassRoom.SubjectId;
                    TempVModel.StandardId  = TempClassRoom.StandardId;
                    TempVModel.Scheduler   = TempClassRoom.Scheduler.JSONStringToObject <ClassSchedule>();
                    TempVModel.ClassActivationThreshold = TempClassRoom.ClassActivationThreshold;
                }
            }
            else
            {
                TempVModel.Scheduler                = new ClassSchedule();
                TempVModel.Scheduler.StartDate      = new DateTime(DateTime.Now.Year, 1, 1);
                TempVModel.Scheduler.EndDate        = new DateTime(DateTime.Now.Year, 12, 31);
                TempVModel.Scheduler.StartTime      = DateTime.Now.ToString("h:mm tt");
                TempVModel.Scheduler.EndTime        = DateTime.Now.AddHours(1).ToString("hh:mm tt");
                TempVModel.ClassActivationThreshold = 60; //default value later may be read from settings
            }
            CommonResponce result = new CommonResponce {
                Stat = isValid, StatusMsg = (isValid ? "" : "Invalid Classroom Id"), StatusObj = null
            };

            return(result);
        }