Exemple #1
0
        public StudentRegisterViewModel GetAllRegisterStudent(string registrationNo)
        {
            SqlConnection            connection      = new SqlConnection(connectionDB);
            string                   query           = @"SELECT  [Student.Register].StudentRegId, [Student.Register].StudentName, Depatment.Name, [Student.Register].Email, [Student.Register].ContactNo, [Student.Register].RegisterDate, [Student.Register].Address
                            FROM Depatment INNER JOIN  [Student.Register] ON Depatment.DepartmentId = [Student.Register].DepartmentId
                            where StudentRegId='" + registrationNo + "'";
            SqlCommand               command         = new SqlCommand(query, connection);
            StudentRegisterViewModel studentRegister = null;

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            // if (reader.HasRows)
            //{
            while (reader.Read())
            {
                studentRegister = new StudentRegisterViewModel();
                studentRegister.StudentRegisterId = reader["StudentRegId"].ToString();
                studentRegister.StudentName       = reader["StudentName"].ToString();
                studentRegister.ContactNo         = Convert.ToInt32(reader["ContactNo"].ToString());
                studentRegister.Address           = reader["Address"].ToString();
                studentRegister.Email             = reader["Email"].ToString();
                studentRegister.DepartmentName    = reader["Name"].ToString();
                studentRegister.RegisterDate      = Convert.ToDateTime(reader["RegisterDate"].ToString());
            }
            reader.Close();
            connection.Close();
            return(studentRegister);
        }
Exemple #2
0
        public ActionResult Student()
        {
            StudentRegisterViewModel model = new StudentRegisterViewModel();

            model.TermsnCondition = "sample terms and condition";
            return(View(model));
        }
Exemple #3
0
        public async Task <IActionResult> Register(StudentRegisterViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var user = new StudentUser()
                {
                    UserName = vm.Email,
                    Email    = vm.Email,
                };

                var result = await userManager.CreateAsync(user, vm.Password);

                if (result.Succeeded)
                {
                    //await signinManager.SignInAsync(user, false);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    foreach (var item in result.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }
                }
            }

            return(View(vm));
        }
        public async Task <ActionResult> Register(StudentRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new STUser {
                    UserName = model.Email, Email = model.Email, RoleName = model.RoleName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    result = await UserManager.AddToRoleAsync(user.Id, model.RoleName);

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("StudentHome", "StudentHome", new { area = "StudentArea" }));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #5
0
        public async Task <IActionResult> AddStudent(StudentRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool isRegistredBefore = (await _studentRepository.FindStudentByNationalId(model.NationalCode)) == null;
                if (isRegistredBefore)
                {
                    ModelState.AddModelError(null, "This student is registered before");
                    return(View());
                }

                long   fileSize = model.PersonalImage?.Length ?? 0;
                string filePath = "";
                if (fileSize > 0)
                {
                    string filename = model.PersonalImage?.FileName ?? "";
                    string ext      = filename.Split('.').Last().ToLower();
                    if (ext.Contains("jpg") || ext.Contains("png") || ext.Contains("jpeg"))
                    {
                        filePath = $"/wwwroot/photos/{Guid.NewGuid()}.{ext}";
                        Directory.CreateDirectory(filePath);
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await model.PersonalImage?.CopyToAsync(stream);

                            await stream.FlushAsync();
                        }
                    }
                }
                var student = new Student()
                {
                    Birthday          = model.Birthday,
                    Email             = model.Email,
                    Name              = model.Surename,
                    Surename          = model.Surename,
                    NationalCode      = model.NationalCode,
                    UserName          = model.Username,
                    Grade             = model.Grade,
                    PersonalImagePath = filePath
                };
                var result = await _userManager.CreateAsync(student, model.Password);

                if (result.Succeeded)
                {
                    var claim = new Claim("Fullname", student.Fullname);
                    await _userManager.AddClaimAsync(student, claim);

                    await _userManager.AddToRoleAsync(student, ValidRoles.Student);

                    return(RedirectToAction("Index"));
                }
            }
            ModelState.AddModelError(null, "Please Check The inputs");
            return(View());
        }
Exemple #6
0
        public ActionResult NewStudentRegistration()
        {
            var batches = _context.Batches.ToList();

            var viewModel = new StudentRegisterViewModel
            {
                Batches = batches
            };

            return(View("NewStudentRegistration", viewModel));
            //return View();
        }
        // GET: Student
        public ActionResult RegisterStudent()
        {
            var model = new StudentRegisterViewModel();

            model.DepartmentSelectListItems = _studentRepository.AllDepatrmint()
                                              .Select(c => new SelectListItem()
            {
                Value = c.Id.ToString(), Text = c.Name
            }).ToList();

            return(View(model));
        }
        [Authorize(Roles = GlobalConstants.AdministratorRoleName)]//only admins can add users
        public ActionResult Register()
        {
            if (!User.IsInRole(GlobalConstants.AdministratorRoleName))//only admins can see the registration screen
            {
                return(RedirectToAction("Index", "Home", new { area = string.Empty }));
            }


            StudentRegisterViewModel model = new StudentRegisterViewModel();


            return(View(model));
        }
        public async Task <ActionResult> Register(StudentRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.UserName,
                    Email    = model.Email,

                    PhoneNumber = model.PhoneNumber,
                };

                IdentityResult result = await UserManager.CreateAsync(user, model.Password);//create the applicationUser through userManager

                if (result.Succeeded)
                {
                    this.UserManager.AddToRole(user.Id, GlobalConstants.StudentRoleName);//assign role of student to newly registered user

                    Student student = new Student();
                    student.ApplicationUserId = user.Id;
                    student.Name = model.Name;
                    //student.ApplicationUser = user;

                    //Mapper.Map<RegisterViewModel, Student>(model, student);//dump the model into the student (in this case, all it does is student.Name = model.Name but in other cases it will apare us a lot of lines of code)
                    //the map is created in frontend/automapperconfig/organizationprofile.cs, here it is just applied.

                    MichtavaResult res = this.studentService.Add(student);//add student to DB through service


                    if (res is MichtavaSuccess)
                    {
                        return(RedirectToAction("Index", "Students", new { area = "Administration" }));//TODO make this work
                    }
                    // return RedirectToAction("Index", "Home", new { area = string.Empty });//getting 404 here
                    else
                    {
                        ModelState.AddModelError(string.Empty, res.Message);
                    }
                }
                else
                {
                    this.AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult StudentRegister(StudentRegisterModel student)
        {
            string registrationNo = "";
            string registerYear   = studentRegisterManager.GetStudentRegisteryear(student.DepartmentId);
            string currentYear    = DateTime.Now.Year.ToString();

            if (registerYear == currentYear)
            {
                string deppartmentCode = studentRegisterManager.GetDepartmentCode(student.DepartmentId);
                //generate registration number
                var code = deppartmentCode.Substring(0, 3);
                var year = DateTime.Now.Year;
                int no   = studentRegisterManager.GetNo(student.DepartmentId);
                //int no = studentRegisterManager.GetNo(student);
                no             = no + 1;
                registrationNo = (code + "-" + year + "-") + (no.ToString().PadLeft(3, '0'));
            }
            else
            {
                string deppartmentCode = studentRegisterManager.GetDepartmentCode(student.DepartmentId);
                //generate registration number
                var code = deppartmentCode.Substring(0, 3);
                var year = DateTime.Now.Year;
                int no   = 0;
                //studentRegisterManager.GetNo(student.DepartmentId);
                //int no = studentRegisterManager.GetNo(student);
                no             = no + 1;
                registrationNo = (code + "-" + year + "-") + (no.ToString().PadLeft(3, '0'));
            }
            //-----------------------
            if (student.ContactNo.Length == 11)
            {
                studentRegisterManager.SaveStudent(student, registrationNo);
                ViewBag.message = "Saved Successfully";
                StudentRegisterViewModel allRegisterStudent = studentRegisterManager.GetAllStudentRegister(registrationNo);
                ViewBag.AllRegisterStudent = allRegisterStudent;
            }
            else
            {
                ViewBag.message = "Enter a valid 11 digit number";
            }

            ViewBag.Departments = departmentManager.GetDepartment();
            //ViewBag.PostBack = true;
            return(View());
        }
Exemple #11
0
        public void Insert(StudentRegisterViewModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("StudentRegister");
            }
            StudentRegister studentRegister = new StudentRegister
            {
                RegNo        = model.RegNo,
                Name         = model.Name,
                Email        = model.Email,
                Mobile       = model.Mobile,
                Address      = model.Address,
                DepartmentId = model.DepartmentId,
                CreatedAt    = model.CreatedAt,
                ModifiedAt   = null
            };

            entities.Add(studentRegister);
            _context.SaveChanges();
        }
Exemple #12
0
        public ActionResult Create(StudentRegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ErrorMessage = "Enter all the required fields in corrent format.";
                return(View(model));
            }

            if (_dbHelper.IsUsernameExists(model.Username))
            {
                model.ErrorMessage = "Username already exists. Please choose another username.";
                return(View(model));
            }

            if (_dbHelper.AddStudent(model.Name, model.Address, model.Age, model.Email, model.Username, model.Password))
            {
                return(RedirectToAction("Index"));
            }

            model.ErrorMessage = "Failed to add new student.";
            return(View(model));
        }
        public ActionResult StudentRegister(StudentRegisterViewModel viewModel)
        {
            ApplicationsForRegistration application = new ApplicationsForRegistration
            {
                FirstName   = viewModel.FirstName,
                SecondName  = viewModel.SecondName,
                MiddleName  = viewModel.MiddleName,
                CardNumber  = viewModel.CardNumber,
                DateOfBirth = viewModel.DateOfBirth,
                GroupId     = viewModel.GroupId,
                Email       = viewModel.Email,
                Login       = viewModel.Login,
                Password    = viewModel.Password
            };

            using (DiaryConnection db = new DiaryConnection())
            {
                db.ApplicationsForRegistration.Add(application);
                db.SaveChanges();
            }
            return(RedirectToAction("ApplicationAccepted"));
        }
Exemple #14
0
        public async Task <IActionResult> EditStudent(int?id)
        {
            var student = await _studentRepository.FindStudentByIdAsync(id);

            if (student == null)
            {
                return(RedirectToAction("Index"));
            }

            var studentView = new StudentRegisterViewModel()
            {
                Birthday     = student.Birthday,
                Email        = student.Email,
                Grade        = student.Grade,
                Name         = student.Name,
                Password     = "",
                Surename     = student.Surename,
                Username     = student.UserName,
                NationalCode = student.NationalCode
            };

            return(View(studentView));
        }
Exemple #15
0
 public void Remove(StudentRegisterViewModel model)
 {
     throw new NotImplementedException();
 }
        public async Task<ActionResult> Register(StudentRegisterViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = this.Mapper.Map<User>(model);
                user.UserName = user.Email;

                var result = await this.UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    this.UserManager.AddToRole(user.Id, "Student");

                    await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    return this.RedirectToAction("Index", "Home");
                }

                this.AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return this.View(model);
        }
Exemple #17
0
        public ActionResult Create()
        {
            var model = new StudentRegisterViewModel();

            return(View(model));
        }
Exemple #18
0
        public async Task <ActionResult> Student(StudentRegisterViewModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var _existUser = await UserManager.FindByEmailAsync(model.Email);

                if (_existUser != null)
                {
                    ViewBag.Message = "Email Already Exists.";
                    ModelState.AddModelError("", "Email Already Exists.");
                    return(View(model));
                }
                //profile upload
                //if (file != null)
                //{
                //    var supportedTypes = new[] { "jpg", "jpeg", "png", "gif" };
                //    var fileExt = System.IO.Path.GetExtension(file.FileName).Substring(1);
                //    //if ((file.ContentLength / 1024 > 1024) || (!supportedTypes.Contains(fileExt)))
                //    //{
                //    //    ViewBag.Message = "Only JPEG/PNG image smaller than 1MB is allowed.";
                //    //    ModelState.AddModelError("", "Only JPEG/PNG image smaller than 1MB is allowed.");
                //    //    return View(model);
                //    //}
                //    if (supportedTypes.Contains(fileExt))
                //    {
                //        var profileImage = Guid.NewGuid() + Path.GetExtension(file.FileName);
                //        file.SaveAs(HttpContext.Server.MapPath("~/Content/images/student/") + profileImage);
                //        model.ProfileImage = profileImage;
                //    }
                //}

                //profile upload
                if (model.File != null)
                {
                    try
                    {
                        var supportedTypes = new[] { "jpg", "jpeg", "png", "gif", "tif" };
                        var fileExt        = System.IO.Path.GetExtension(model.File.FileName).Substring(1);
                        if (supportedTypes.Contains(fileExt.ToLower()))
                        {
                            var profileImage = Guid.NewGuid() + Path.GetExtension(model.File.FileName);
                            model.File.SaveAs(HttpContext.Server.MapPath("~/Content/images/student/") + profileImage);
                            model.ProfileImage = profileImage;
                        }
                    }
                    catch (Exception exi)
                    {
                    }
                }

                var user = new ApplicationUser
                {
                    UserName      = model.Email,
                    Email         = model.Email,
                    Gender        = model.Gender,
                    FirstName     = model.FirstName,
                    LastName      = model.LastName,
                    PhoneNumber   = model.Mobile,
                    Address       = model.Address,
                    City          = model.City,
                    TimeZone      = model.TimeZone,
                    Country       = model.Country,
                    Zip           = model.Zip,
                    Bio           = model.Bio,
                    StudentSchool = model.StudentSchool,
                    StudentGrade  = model.StudentGrade,
                    Hobbies       = model.Hobbies,
                    ProfileImage  = model.ProfileImage,
                    //DOB = DateTime.Now.AddYears(-29),
                    CreatedDate = DateTime.Now,
                    //UpdatedDate = DateTime.Now
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Student");
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                    await UserManager.SendEmailAsync(user.Id, "Confirm your account",
                                                     "Hi " + model.FirstName + ",<br/><br/>"
                                                     + "Thanks for registering with us.<br/>"
                                                     + "Please confirm your student account by clicking <a href=\"" + callbackUrl + "\">" + callbackUrl + "</a><br/><br/>"
                                                     + "Regards, <br/><a href='http://instanttutors.org/' target='_blank'>Instant Tutors Team</a>");

                    //await EmailSender.SendEmailAsync("Confirm your account", "Hi " + model.FirstName + ",<br/><br/>"
                    //    + "Thanks for registering with us.<br/>"
                    //    + "Please confirm your student account by clicking <a href=\"" + callbackUrl + "\">" + callbackUrl + "</a><br/><br/>"
                    //    + "Regards, <br/><a href='http://instanttutors.org/' target='_blank'>Instant Tutors @" + DateTime.Now.Year + "</a>", user.Email, true);

                    try
                    {
                        var _subject = "New Student Signup | instanttutors.org";
                        var _body    = "<h5>New Student Signup</h5>" + ",<br/><br/>"
                                       + "<b>Fullname:</b> " + model.FirstName + " " + model.LastName + "<br/>"
                                       + "<b>Email Address:</b> " + model.Email + "<br/>"
                                       + "<b>Mobile:</b> " + model.Mobile + "<br/><br/>"
                                       + "<a href='http://instanttutors.org/' target='_blank'>Instant Tutors</a> @ " + DateTime.Now.Year;

                        await EmailSender.SendEmailAsync(_subject, _body);

                        await SMSSender.SMSSenderAsync("Thanks! Please verify your student a/c " + callbackUrl + " <br>Instant Tutors Team", user.PhoneNumber);

                        //await SMSSender.SMSSenderAsync("New Student Registration - Name: " + user.FirstName + " " + user.LastName + ", M: " + user.PhoneNumber + ", Email: " + user.Email);
                    }
                    catch { }

                    ModelState.Clear();
                    ViewBag.success = "<ul><li><p style='color:green'>Successfully registered!! An email has been sent to your email address, Please verify.</p></li></ul>";
                    return(View(model));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #19
0
        public async Task <IActionResult> RegisterCourse(StudentRegisterViewModel srvm)
        {
            var courses = _adminRepository.Courses();

            if (ModelState.IsValid)
            {
                ClaimsPrincipal currentUser = User;
                var             user        = await _userManager.GetUserAsync(currentUser);

                var student = _studentRepository.GetStudentByUser(user);
                var course  = _schoolContext.Course.SingleOrDefault(c => c.CodeID == srvm.CourseID);
                var check   = _schoolContext.Enrollments.Where(e => e.StudentID == student.StudentID).Any(e => e.CourseID == srvm.CourseID);
                if (check)
                {
                    ModelState.AddModelError("", "You can't register the same Course more than once");
                    return(View(new StudentRegisterViewModel()
                    {
                        Courses = courses
                    }));
                }
                var enrollment = new Enrollment()
                {
                    CourseID  = course.CodeID,
                    StudentID = student.StudentID
                };
                int NewCredits = student.CreditsTaken + course.NumOfCredits;
                if (NewCredits > 30)
                {
                    ModelState.AddModelError("", "You can't register to more than 30 credits worth of courses");
                    return(View(new StudentRegisterViewModel()
                    {
                        Courses = courses
                    }));
                }
                else
                {
                    student.CreditsTaken = NewCredits;
                }
                _schoolContext.Students.Update(student);
                _schoolContext.Enrollments.Add(enrollment);
                if (_schoolContext.SaveChanges() == 0)
                {
                    ModelState.AddModelError("", "Something went wrong while updating database, please try again later");
                    return(View(new StudentRegisterViewModel()
                    {
                        Courses = courses
                    }));
                }
            }
            else
            {
                ModelState.AddModelError("", "Something went wrong while updating database, please try again later");
                return(View(new StudentRegisterViewModel()
                {
                    Courses = courses
                }));
            }

            return(View(new StudentRegisterViewModel()
            {
                Courses = courses
            }));
        }
Exemple #20
0
 public void SoftDelete(StudentRegisterViewModel model)
 {
     throw new NotImplementedException();
 }