Beispiel #1
0
 public long CreateNewStudent(StudentViewModel objViewModel)
 {
     Student objStudent = new Student();
     objStudent.UserId = objViewModel.UserId;
     objStudent.CourseId = objViewModel.CourseId;
     objStudent.DepartmentId = objViewModel.DepartmentId;
     objStudent.ClassId = objViewModel.ClassId;
     objStudent.SectionId = objViewModel.SectionId;
     objStudent.RollNo = objViewModel.RollNo;
     objStudent.InsertedOn = DateTime.Now;
     objStudent.InsertedBy = objViewModel.InsertedBy;
     objStudent.Email = objViewModel.Email;
     objStudent.OrganizationId = objViewModel.OrganizationId;
     objStudent.FullName = objViewModel.Profile.FirstName + " " + objViewModel.Profile.LastName;
     return objStudent.StudentId = this.CreateStudent(objStudent);
 }
Beispiel #2
0
        public ActionResult CreateStudent(StudentViewModel objViewModel)
        {
            string token = repository.CreateToken(objViewModel, _userStatistics.UserId, _userStatistics.OrganizationId);
            if (!(string.IsNullOrEmpty(token)))
            {
                long userId = WebSecurity.RegisterNewUser(objViewModel.Email, "none", objViewModel.Email, false, objViewModel.Profile.FirstName, objViewModel.Profile.LastName, objViewModel.OrganizationId, token);
                DBConnectionString.Profile Profile = new DBConnectionString.Profile();
                if (userId != -1)
                {
                    Profile.UserId = userId;
                    Profile.Title = objViewModel.Profile.Title;
                    Profile.Address1 = "none";
                    Profile.Address2 = "none";
                    Profile.InsertedOn = DateTime.Now;
                    Profile.EmailAddress1 = objViewModel.Email;
                    Profile.HomeTelephoneNumber = objViewModel.Profile.HomeTelephoneNumber;
                    Profile.SecurityQuestionId = 1;
                    Profile.SecurityAnswer = "none";
                    Profile.DateOfBirth = objViewModel.Profile.DateOfBirth;
                    Profile.ModifiedOn = null;
                    Profile.MobileNumber = objViewModel.Profile.MobileNumber;

                    int recAffected = Convert.ToInt32(Profile.Insert());

                    string roleName = UserRoles.Student.ToString(); //((UserRoles)Convert.ToInt16(Token.RoleId)).ToString();
                    Roles.AddUserToRole(objViewModel.Email, roleName);
                    objViewModel.UserId = userId;

                    objViewModel.InsertedBy = _userStatistics.UserId;
                    objViewModel.OrganizationId = _userStatistics.OrganizationId;
                    objViewModel.StudentId = repository.CreateNewStudent(objViewModel);
                    if (objViewModel.StudentId != -1)
                    {
                        this.AssignGroup(objViewModel.GroupIds, userId);
                        this.AssignSubject(objViewModel.SubjectIds, userId, objViewModel.StudentId);
                        SaveFiles(token, this.GetType().Name, objViewModel.StudentId);
                        EmailHandler.Utilities.SendRegistationEmail(token, objViewModel.Email);
                    }
                    return RedirectToAction("Index");
                }
            }
            return View(this.LoadViewModel());
        }
Beispiel #3
0
 public string CreateToken(StudentViewModel objViewModel, long userId, long organizationId)
 {
     int recordAffected = 0;
     DBConnectionString.RegistrationToken registrationToken = new DBConnectionString.RegistrationToken();
     registrationToken.OrganizationId = organizationId;
     registrationToken.CourseId = (int)objViewModel.CourseId;
     registrationToken.ClassId = objViewModel.ClassId;
     registrationToken.SectionId = objViewModel.SectionId;
     if (objViewModel.DepartmentId != null)
     {
         registrationToken.DepartmentId = (int)objViewModel.DepartmentId;
     }
     registrationToken.Token = UserStatistics.GenerateToken();
     registrationToken.CreatedBy = userId;
     registrationToken.InsertedOn = DateTime.Now;
     registrationToken.RoleId = (int)UserRoles.Student;
     recordAffected = Convert.ToInt32(registrationToken.Insert());
     if (recordAffected > 0)
     {
         return registrationToken.Token;
     }
     return string.Empty;
 }
Beispiel #4
0
 public ActionResult Details(long id)
 {
     StudentViewModel objViewModel = new StudentViewModel();
     objViewModel = this.repository.GetStudents(_userStatistics.OrganizationId, id);
     PetaPoco.Database db = new PetaPoco.Database("DBConnectionString");
     objViewModel.GroupNames = string.Join(",", db.Query<string>("select GroupName from [Group] as G join UserGroup As UG on G.GroupId = UG.GroupId where UG.UserId = @0", objViewModel.UserId));
     objViewModel.SubjectNames = string.Join(",", db.Query<string>("select SubjectName from Subjects as S join UserSubjects As US on S.SubjectId = US.SubjectId where US.UserId = @0", objViewModel.UserId));
     return View(objViewModel);
 }
Beispiel #5
0
 public StudentViewModel LoadViewModel()
 {
     SelectList classList = null;
     SelectList courseList = null;
     SelectList sectionList = null;
     SelectList departmentList = null;
     this.LoadSelectLists(out  classList, out  courseList, out  sectionList, out  departmentList, false);
     StudentViewModel objViewModel = new StudentViewModel();
     objViewModel.CourseList = courseList;
     objViewModel.DepartmentList = departmentList;
     objViewModel.ClassList = classList;
     objViewModel.SectionList = sectionList;
     return objViewModel;
 }
Beispiel #6
0
        public ActionResult Edit(StudentViewModel objViewModel)
        {
            if (this.repository.UpdateStudent(objViewModel))
            {
                return RedirectToAction("Index");
            }
            SelectList classList = null;
            SelectList courseList = null;
            SelectList sectionList = null;
            SelectList departmentList = null;
            this.LoadSelectLists(out  classList, out  courseList, out  sectionList, out  departmentList, true, objViewModel.OrganizationId, objViewModel.CourseId, objViewModel.DepartmentId, objViewModel.ClassId, objViewModel.SectionId);
            objViewModel.CourseList = courseList;
            objViewModel.DepartmentList = departmentList;
            objViewModel.ClassList = classList;
            objViewModel.SectionList = sectionList;

            return View(objViewModel);
        }
Beispiel #7
0
        public ActionResult Edit(long id)
        {
            SelectList classList = null;
            SelectList courseList = null;
            SelectList sectionList = null;
            SelectList departmentList = null;
            StudentViewModel objViewModel = new StudentViewModel();
            objViewModel = this.repository.GetStudents(_userStatistics.OrganizationId, id);
            this.LoadSelectLists(out  classList, out  courseList, out  sectionList, out  departmentList, true, objViewModel.OrganizationId, objViewModel.CourseId, objViewModel.DepartmentId, objViewModel.ClassId, objViewModel.SectionId);
            objViewModel.CourseList = courseList;
            objViewModel.DepartmentList = departmentList;
            objViewModel.ClassList = classList;
            objViewModel.SectionList = sectionList;

            return View(objViewModel);
        }
Beispiel #8
0
        public bool UpdateStudent(StudentViewModel objViewModel)
        {
            PetaPoco.Database db = new PetaPoco.Database("DBConnectionString");

            DBConnectionString.User user = DBConnectionString.User.SingleOrDefault(objViewModel.UserId);
            DBConnectionString.Student student = DBConnectionString.Student.SingleOrDefault(objViewModel.StudentId);
            DBConnectionString.Profile profile = db.Query<DBConnectionString.Profile>("Select * from  profile where UserId = @0", student.UserId).SingleOrDefault();
            db.BeginTransaction();
            try
            {
                if (user != null)
                {
                    user.FirstName = objViewModel.FirstName;
                    user.LastName = objViewModel.LastName;
                    user.Update();
                }

                if (student != null)
                {
                    student.ClassId = objViewModel.ClassId;
                    student.CourseId = objViewModel.CourseId;
                    student.DepartmentId = objViewModel.DepartmentId;
                    student.Email = objViewModel.Email;
                    student.FullName = objViewModel.FirstName + " " + objViewModel.LastName;
                    student.ModifiedBy = objViewModel.ModifiedBy;
                    student.ModifiedOn = objViewModel.ModifiedOn;
                    student.SectionId = objViewModel.SectionId;
                    student.Update();
                }

                if (profile != null)
                {
                    profile.Title = objViewModel.Title;
                    profile.DateOfBirth = objViewModel.DateOfBirth;
                    profile.MobileNumber = objViewModel.MobileNumber;
                    profile.HomeTelephoneNumber = objViewModel.HomeTelephoneNumber;
                    profile.EmailAddress1 = objViewModel.Email;
                    profile.Update();
                }

                //var subjectIdArray = objViewModel.SubjectIds.Split(',');
                //foreach (var subjectId in subjectIdArray)
                //{
                //    DBConnectionString.UserSubject userSubject = db.Query<DBConnectionString.UserSubject>("select * from UserSubjects where UserId = @0 and SubjectId = @1", objViewModel.UserId, subjectId).SingleOrDefault();
                //    if (userSubject == null)
                //    {
                //        userSubject.UserId = objViewModel.UserId.Value;
                //        userSubject.SubjectId = Convert.ToInt64(subjectId);
                //        userSubject.InsertedOn = DateTime.Now;
                //        userSubject.InsertedBy = objViewModel.InsertedBy;
                //        userSubject.Update();
                //    }
                //}

                db.CompleteTransaction();
                return true;
            }
            catch
            {
                db.AbortTransaction();
                return false;
            }
        }