Beispiel #1
0
        public async Task <CommonResponce> UpdateStudentProfile(StudentProfileVM oStudentToUpdate)
        {
            CommonResponce result = new CommonResponce {
                Stat = false, StatusMsg = ""
            };
            bool isValid = false;

            try
            {
                var oStudent = await _DBStudentRepository.GetStudentByStudentId(oStudentToUpdate.Id).ConfigureAwait(false);

                if (oStudent != null)
                {
                    oStudent.RegNo      = oStudentToUpdate.RegNo;
                    oStudent.Name       = oStudentToUpdate.Name;
                    oStudent.Address    = oStudentToUpdate.Address;
                    oStudent.Email      = oStudentToUpdate.Email;
                    oStudent.ContactNo  = oStudentToUpdate.ContactNo;
                    oStudent.StandardId = oStudentToUpdate.StandardId;
                    _commonRepository.Update(oStudent);
                    result.Stat      = true;
                    result.StatusMsg = "Student information updated successfully";
                }
                else      // student not found
                {
                    result.StatusMsg = "Not a valid Student";
                }
            }
            catch { result.Stat = isValid; result.StatusMsg = "Failed to update student information"; }
            return(result);
        }
Beispiel #2
0
        public async Task <IActionResult> StudentProfile()
        {
            CreateBreadCrumb(new[] { new { Name = "Home", ActionUrl = "#" },
                                     new { Name = "Student", ActionUrl = "/Student/StudentProfile" } });
            List <StandardMasterBM> oAllStandards = await _StandardMasterService.GetAllStandards(500); // get all standards

            BaseViewModel VModel     = null;
            var           TempVModel = new StudentProfileVM();

            TempVModel.AllStandards.AddRange(oAllStandards); // populate the list

            //}
            //*****get user avtar************
            string UsrImgPath = string.Format("~/AppFileRepo/UserAvatar/{0}.{1}", TempVModel.LoginId, "jpg");

            //string UsrImgPath = string.Format("{0}\\{1}.{2}", Path.Combine(GetBaseService().GetAppRootPath(), "AppFileRepo", "UserAvatar"), TempVModel.LoginId, "jpg");
            //if (System.IO.File.Exists(UsrImgPath))
            //{
            //    UsrImgPath = string.Format("~/AppFileRepo/UserAvatar/{0}.{1}", TempVModel.LoginId, "jpg");
            //}
            //else
            //{
            //    //if (CurrentUserInfo.UserGender.Equals("M"))
            //        UsrImgPath = "~/img/avatar5.png";
            //    //else
            //    //    UsrImgPath = "~/img/avatar3.png";
            //}
            TempVModel.StudentImgPath     = UsrImgPath;
            TempVModel.AttachStudentImage = new FileUploadInfo();

            //*******************************
            VModel = await GetViewModel(TempVModel);

            return(View("~/Views/Master/StudentProfile.cshtml", VModel));
        }
Beispiel #3
0
        public async Task <CommonResponce> InsertStudentProfile(StudentProfileVM StudentToInsert)
        {
            CommonResponce result = new CommonResponce {
                Stat = false, StatusMsg = ""
            };
            CommonResponce DataValidationResult = new CommonResponce {
                Stat = false, StatusMsg = ""
            };
            bool        isValid  = false;
            Tblmstudent oStudent = null;

            try
            {
                oStudent = new Tblmstudent
                {
                    RegNo       = StudentToInsert.RegNo,
                    Name        = StudentToInsert.Name,
                    Address     = StudentToInsert.Address,
                    Email       = StudentToInsert.Email,
                    ContactNo   = StudentToInsert.ContactNo,
                    StandardId  = StudentToInsert.StandardId,
                    LoginUserId = StudentToInsert.LoginUserId
                };
                //isValid = await _commonRepository.Insert(_mapper.Map<Tblmstudent>(StudentToInsert));
                isValid = await _commonRepository.Insert(oStudent);

                result.Stat      = isValid;
                result.StatusMsg = "Student added successfully";
            }
            catch { result.Stat = isValid; result.StatusMsg = "Failed to add new student"; }
            return(result);
        }
Beispiel #4
0
        public async Task <CommonResponce> CheckDataValidation(StudentProfileVM StudentToInsert, bool IsAdd)
        {
            CommonResponce result = new CommonResponce {
                Stat = true, StatusMsg = ""
            };
            Tblmstudent oStudent = null;

            if (IsAdd)  // check validation while adding a new student
            {
                oStudent = await _DBStudentRepository.GetStudentByRegNo(StudentToInsert.RegNo).ConfigureAwait(false);

                if (oStudent != null)
                {
                    result.Stat = false; result.StatusMsg = "Registration No already in use";
                }
                else
                {
                    oStudent = await _DBStudentRepository.GetStudentByEmailID(StudentToInsert.Email);

                    if (oStudent != null)
                    {
                        result.Stat = false; result.StatusMsg = "Email Id already in use";
                    }
                }
            }
            else  // validation while updating
            {
                oStudent = await _DBStudentRepository.GetStudentByRegNo(StudentToInsert.RegNo).ConfigureAwait(false);

                if (oStudent != null)                      // got result
                {
                    if (StudentToInsert.Id != oStudent.Id) // different student with same reg no
                    {
                        result.Stat = false; result.StatusMsg = "Registration No already in use";
                    }
                    else // same student found check duplicate email id
                    {
                        oStudent = await _DBStudentRepository.GetStudentByEmailID(StudentToInsert.Email);

                        if (oStudent != null)
                        {
                            if (StudentToInsert.Id != oStudent.Id)  // different student with same email id
                            {
                                result.Stat = false;
                            }
                            result.StatusMsg = "Email Id already in use";
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #5
0
        public async Task <IActionResult> UpdateStudentProfile(int StudentID)
        {
            CreateBreadCrumb(new[] { new { Name = "Home", ActionUrl = "#" },
                                     new { Name = "Student", ActionUrl = "/Student/UpdateStudentProfile" } });

            BaseViewModel  VModel = null;
            CommonResponce CR     = await _StudentService.GetStudentByStudentId(StudentID);

            if (CR.Stat)
            {
                List <StandardMasterBM> oAllStandards = await _StandardMasterService.GetAllStandards(500);

                Student StudentInfo = (Student)CR.StatusObj;
                //*****get user avtar************

                //string UsrImgPath = string.Format("{0}\\{1}.{2}", Path.Combine(GetBaseService().GetAppRootPath(), "AppFileRepo\\StudentAvatar"), StudentInfo.RegNo, "jpg");
                //if (System.IO.File.Exists(UsrImgPath))
                //    UsrImgPath = string.Format("~/AppFileRepo/StudentAvatar/{0}.{1}", StudentInfo.RegNo, "jpg");
                //else
                //    UsrImgPath = "~/img/avatar5.png";

                var TempVModel = new StudentProfileVM
                {
                    Id                 = StudentInfo.Id,
                    Name               = StudentInfo.Name,
                    RegNo              = StudentInfo.RegNo,
                    Address            = StudentInfo.Address,
                    ContactNo          = StudentInfo.ContactNo,
                    Email              = StudentInfo.Email,
                    StandardId         = StudentInfo.StandardId,
                    StudentImgPath     = "",
                    AttachStudentImage = new FileUploadInfo()
                };
                TempVModel.AllStandards.AddRange(oAllStandards);// all standard list
                //var TempVModel = new StudentProfileVM();
                if (StudentInfo.LoginUserId != null)
                {
                    var AppVM = await _AppUserService.GetAppUserByID((int)StudentInfo.LoginUserId);

                    if (AppVM != null)
                    {
                        TempVModel.LoginId = AppVM.UserId;
                        string UsrImgPath = string.Format("~/AppFileRepo/UserAvatar/{0}.{1}", TempVModel.LoginId, "jpg");
                        TempVModel.StudentImgPath = UsrImgPath;
                    }
                }
                VModel = await GetViewModel(TempVModel);
            }
            //*******************************
            return(View("~/Views/Master/UpdateStudentProfile.cshtml", VModel));
        }
Beispiel #6
0
        public async Task <JsonResult> UpdateStudentProfile(StudentProfileVM model)
        {
            CommonResponce result = null;

            if (ModelState.IsValid)
            {
                result = await _StudentService.CheckDataValidation(model, false);

                if (!result.Stat)// validation failed
                {
                    return(Json(new { stat = false, msg = result.StatusMsg }));
                }
                result = await _StudentService.UpdateStudentProfile(model);

                if (result.Stat == true)
                {
                    var CurrentUserInfo = GetLoginUserInfo();// get current user
                    await GetBaseService().AddActivity(ActivityType.Update, CurrentUserInfo.UserID, CurrentUserInfo.UserName, "Student Profile", "Updated Student profile");

                    if (model.AttachStudentImage.FileSize > 0)
                    {
                        var RtnMsg = GetBaseService().DirectoryFileService.CreateUserAvatarFromBase64String(GetBaseService().GetAppRootPath(), model.LoginId, model.AttachStudentImage.FileContentsBase64);
                        model.StudentImgPath = RtnMsg.StatusMsg;
                        //string StudentImgPath = Path.Combine(GetBaseService().GetAppRootPath(), "AppFileRepo", "UserAvatar");
                        //if (GetBaseService().DirectoryFileService.CreateDirectoryIfNotExist(StudentImgPath))
                        //{
                        //    StudentImgPath = Path.Combine(StudentImgPath, string.Format("{0}.{1}", model.LoginId, "jpg"));
                        //    if (GetBaseService().DirectoryFileService.CreateFileFromBase64String(model.AttachStudentImage.FileContentsBase64, StudentImgPath))
                        //    {
                        //        model.StudentImgPath = string.Format("~/AppFileRepo/UserAvatar/{0}.{1}?r={2}", model.LoginId, "jpg", DateTime.Now.Ticks.ToString());
                        //        //model.BUserImgPath = model.StudentImgPath; // update the Student avatar
                        //    }
                        //}
                    }

                    return(Json(new { stat = true, msg = "Student Profile Updated", rtnUrl = "/Student/Students" }));
                }
                else
                {
                    return(Json(new { stat = false, msg = result.StatusMsg }));
                }
            }
            else
            {
                return(Json(new { stat = false, msg = "Invalid Student Profile" }));
            }
        }
Beispiel #7
0
        public async Task <JsonResult> StudentProfile(StudentProfileVM model)
        {
            CommonResponce result = null;
            StringBuilder  rtnMsg = new StringBuilder();

            if (ModelState.IsValid)
            {
                result = await _StudentService.CheckDataValidation(model, true);

                if (!result.Stat)// validation failed
                {
                    return(Json(new { stat = false, msg = result.StatusMsg }));
                }
                result = await _AppUserService.GetUserProfile(model.LoginId); // check same login id

                if (result.Stat)                                              // login id exists
                {
                    return(Json(new { stat = false, msg = "Login Id already in use" }));
                }
                AppUserVM oAppUserVM = new AppUserVM(); // add an user in the user table
                oAppUserVM.Name     = model.Name;
                oAppUserVM.UserId   = model.LoginId;
                oAppUserVM.UserType = "U";// User
                oAppUserVM.Email    = model.Email;
                oAppUserVM.Mobile   = model.ContactNo;
                oAppUserVM.IsActive = true;
                string   ResetContext = Guid.NewGuid().ToString().Replace("-", "RP");
                DateTime PassValidity = DateTime.Now.AddDays(3); //validity for 1 day
                result = await _AppUserService.SaveAppUserAsync(oAppUserVM, ResetContext, PassValidity).ConfigureAwait(false);

                if (!result.Stat)// user addition failed
                {
                    return(Json(new { stat = false, msg = result.StatusMsg }));
                }
                else
                {
                    model.LoginUserId = result.StatusObj;
                    result            = await _StudentService.InsertStudentProfile(model);

                    if (result.Stat == true)
                    {
                        rtnMsg.Append("Student Profile Inserted.");
                        //save the user picture
                        if (model.AttachStudentImage.FileSize > 0)
                        {
                            var RtnMsg = GetBaseService().DirectoryFileService.CreateUserAvatarFromBase64String(GetBaseService().GetAppRootPath(), model.LoginId, model.AttachStudentImage.FileContentsBase64);
                            model.StudentImgPath = RtnMsg.StatusMsg;
                            //string StudentImgPath = Path.Combine(GetBaseService().GetAppRootPath(), "AppFileRepo", "UserAvatar");
                            //if (GetBaseService().DirectoryFileService.CreateDirectoryIfNotExist(StudentImgPath))
                            //{
                            //    StudentImgPath = Path.Combine(StudentImgPath, string.Format("{0}.{1}", model.LoginId, "jpg"));
                            //    if (GetBaseService().DirectoryFileService.CreateFileFromBase64String(model.AttachStudentImage.FileContentsBase64, StudentImgPath))
                            //    {
                            //        model.StudentImgPath = string.Format("~/AppFileRepo/UserAvatar/{0}.{1}?r={2}", model.LoginId, "jpg", DateTime.Now.Ticks.ToString());
                            //        //model.BUserImgPath = model.StudentImgPath; // update the Student avatar
                            //    }
                            //}
                        }
                        var CurrentUserInfo = GetLoginUserInfo();// get current user
                        await GetBaseService().AddActivity(ActivityType.Update, CurrentUserInfo.UserID, CurrentUserInfo.UserName, "Student Profile", "Inserted Student profile");

                        await _JobService.AddNewUserCreateEmailJob(Convert.ToInt64(CurrentUserInfo.ID), model.Name, model.Email, GetAppRootUrl(), ResetContext);

                        return(Json(new { stat = true, msg = rtnMsg.ToString(), rtnUrl = "/Student/Students" }));
                    }
                    else
                    {
                        return(Json(new { stat = false, msg = result.StatusMsg }));
                    }
                }
            }
            else
            {
                return(Json(new { stat = false, msg = result.StatusMsg }));
            }
        }
        StudentProfileVM GetStudentFullProfile(string userId)
        {
            //Student Info
            var studentInfo = _repoStud.GetAll().Include(u => u.User).SingleOrDefault(u => u.ApplicationUserId == userId);
            StudentProfileVM studentProfile = new StudentProfileVM()
            {
                ProfileId         = studentInfo.Id,
                BirthDate         = studentInfo.User.BirthDate,
                Email             = studentInfo.User.Email,
                FirstVisit        = studentInfo.FirstVisit,
                Info              = studentInfo.Info,
                Username          = studentInfo.User.Name,
                Gender            = studentInfo.User.Gender,
                Image             = studentInfo.Image,
                University        = studentInfo.Universty,
                UniverstyYearFrom = studentInfo.UniverstyYearFrom,
                UniverstyYearTo   = studentInfo.UniverstyYearTo,
                SchholYearFrom    = studentInfo.SchholYearFrom,
                SchholYearTo      = studentInfo.SchholYearTo,
                UserId            = studentInfo.ApplicationUserId,
                School            = studentInfo.School,
                Title             = studentInfo.Title
            };
            //Student Skills
            var allSkills = GetStudentSkills(userId);
            List <StudentSkillVM> skillsList = new List <StudentSkillVM>();

            foreach (var skill in allSkills)
            {
                StudentSkillVM studentSkill = new StudentSkillVM()
                {
                    Id        = skill.Id,
                    SkillName = skill.Skill.Name
                };
                skillsList.Add(studentSkill);
            }
            studentProfile.Skills = skillsList;
            //End Student Skills
            //Student Exams
            var allExams = GetStudentExams(userId);
            List <StudentExamVM> examsList = new List <StudentExamVM>();

            foreach (var exam in allExams)
            {
                StudentExamVM studentExam = new StudentExamVM()
                {
                    ExamName      = exam.Exam.Title,
                    StudentDegree = exam.Degree
                };
                examsList.Add(studentExam);
            }
            studentProfile.Exams = examsList;
            //End Student Exams
            //Student Courses
            var allCourses = GetStudentCourses(userId);
            List <StudentCourseVM> coursesList = new List <StudentCourseVM>();

            foreach (var course in allCourses)
            {
                StudentCourseVM studentCourse = new StudentCourseVM()
                {
                    CourseName = course.Course.Name,
                    Info       = course.Course.Info
                };
                coursesList.Add(studentCourse);
            }
            studentProfile.Courses = coursesList;
            //End Student Courses
            //Student Firneds
            var allFriends = GetStudentFriends(userId);
            List <StudentFollowingVM> finedsList = new List <StudentFollowingVM>();

            foreach (var frined in allFriends)
            {
                var friendData = GetStudent(frined.FriendTwoId);
                if (friendData != null)
                {
                    StudentFollowingVM studentFriend = new StudentFollowingVM()
                    {
                        Id          = frined.Id,
                        Name        = frined.FriendTwo.Name,
                        FriendId    = frined.FriendTwo.Id,
                        Title       = friendData.Title,
                        FriendImage = friendData.Image,
                        Gender      = friendData.User.Gender
                    };
                    finedsList.Add(studentFriend);
                }
            }
            studentProfile.Friends = finedsList;
            //End Student Firneds
            //Student Questions
            var allQuestions = GetStudentQuestions(userId);
            List <StudentQuestionVM> questionsList = new List <StudentQuestionVM>();

            foreach (var question in allQuestions)
            {
                var studentData = GetStudent(question.UserId);
                if (studentData != null)
                {
                    StudentQuestionVM studentQuestion = new StudentQuestionVM()
                    {
                        Id           = question.Id,
                        Dislikes     = question.Dislikes,
                        Likes        = question.Likes,
                        QuestionHead = question.QuestionHead,
                        Username     = question.User.Name,
                        Image        = studentData.Image,
                        UserId       = question.UserId
                    };

                    List <QuestionAnswerVM> questionAnswersList = new List <QuestionAnswerVM>();
                    foreach (var answer in question.Answers)
                    {
                        QuestionAnswerVM Answer = new QuestionAnswerVM()
                        {
                            Answer   = answer.QuestionAnswer,
                            Id       = answer.Id,
                            UserId   = answer.UserId,
                            Username = answer.User.Name,
                            //UserImage = answer.User.Student.Image
                        };
                        questionAnswersList.Add(Answer);
                    }//End Answers ForLoop
                    studentQuestion.Answers = questionAnswersList;

                    questionsList.Add(studentQuestion);
                }
            }//End Questions ForLoop
            studentProfile.Questions = questionsList;
            //End Student Questions

            return(studentProfile);
        }//End Get Profile