Ejemplo n.º 1
0
 //
 // GET: /Student/Create
 public ActionResult Create()
 {
     var student = new Student();
     student.Init();
     foreach (var course in Academy.Current.Courses)
     {
         student.CmbCourse.Add(new SelectListItem() { Text= course.Name,Value = course.Id + "" });
     }
     return View(student);
 }
        public async Task<IHttpActionResult> PostStudent(Student Student)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _context.Students.Add(Student);

            return CreatedAtRoute("DefaultApi", new { id = Student.Id }, Student);
        }
        // PUT: api/Students/5
        public async Task<IHttpActionResult> PutStudent(int id, Student Student)
        {
            var StudentFromPersist = _context.Students.FirstOrDefault(item => item.Id == id);

            if (StudentFromPersist == null)
                return NotFound();

            StudentFromPersist.Name = Student.Name;
            StudentFromPersist.GroupId = Student.GroupId;

            return Ok();
        }
Ejemplo n.º 4
0
        public ActionResult Create(Student student)
        {
            try
            {
                Academy.Current.AddOrUpdate(student);
                var body = MVCUtils.GetRazorViewAsString(student, "~/Views/Shared/Templates/tpl_student_create.cshtml");
                Constants.mailer.SendMail(Constants.mailer.USER, student.Email,Constants.Email_Fahm_e_Islam , Constants.Email_BCC,
                "Your Account Has Been Created.", body, Constants.App_Title + " Team");

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 5
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser
                {
                    UserName = model.Username,
                    Email = model.Email,

                };
               
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (model.SignupAS == "1")
                    {
                        var roleresult = UserManager.AddToRole(user.Id, Status.Student);
                        Student stu = new Student();
                        stu.StudentID = new Guid(user.Id);
                        stu.DateCreated = DateTime.Today;
                        Random rnd = new Random();
                        int filename = rnd.Next(1, 4);
                        stu.ProfileImage = "/Profiles/default/" + filename + ".png";
                        stu.Username = user.UserName;
                        _dbContext.Students.Add(stu);

                        Notifications notify = new Notifications();
                        notify.ID = Guid.NewGuid();
                        notify.isRead = false;
                        notify.Message = "/Profiles/default/admin.png^Admin^You have successfully created your account. You can click ask question to post your first question.";
                        notify.UserName = stu.Username;
                        notify.postedTime = DateTime.Now;
                        _dbContext.notifications.Add(notify);

                        Notifications notify2 = new Notifications();
                        notify2.ID = Guid.NewGuid();
                        notify2.isRead = false;
                        notify2.Message = "/Profiles/default/admin.png^Admin^We now have Arabic Language support as well.";
                        notify2.UserName = stu.Username;
                        notify2.postedTime = DateTime.Now;
                        _dbContext.notifications.Add(notify2);

                        _dbContext.SaveChanges();

                    }
                    else
                    {
                        var roleresult = UserManager.AddToRole(user.Id, Status.Tutor);
                        Tutor tutor = new Tutor();
                        tutor.DateOfBirth = DateTime.Today;
                        tutor.TutorID = new Guid(user.Id);
                        tutor.DateCreated = DateTime.Today;
                        tutor.IsCompletedProfile = false;
                        tutor.Username = user.UserName;
                        Random rnd = new Random();
                        int filename = rnd.Next(1, 4);
                        tutor.ProfileImage = "/Profiles/default/" + filename + ".png";
                        _dbContext.Tutors.Add(tutor);

                        Notifications notify = new Notifications();
                        notify.ID = Guid.NewGuid();
                        notify.isRead = false;
                        notify.Message = "/Profiles/default/admin.png^Admin^Please complete your profile so that you have full access.";
                        notify.UserName = tutor.Username;
                        notify.postedTime = DateTime.Now;
                        _dbContext.notifications.Add(notify);

                        _dbContext.SaveChanges();
                    }


                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                       
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Ejemplo n.º 6
0
        public async Task<ActionResult> Register(StudentRegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Username, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
              
                if (result.Succeeded)
                {
                    var roleresult = UserManager.AddToRole(user.Id, "Student");
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    Student stu = new Student();
                    stu.StudentID = new Guid(user.Id);
                    stu.DateCreated = DateTime.Today;
                    Random rnd = new Random();
                    int filename = rnd.Next(1, 4);
                    stu.ProfileImage = "/Profiles/default/" + filename + ".png";
                    stu.Username = user.UserName;
                    _dbContext.Students.Add(stu);
                    _dbContext.SaveChanges();

                    Notifications notify = new Notifications();
                    notify.ID = Guid.NewGuid();
                    notify.isRead = false;
                    notify.Message = "/Profiles/default/admin.png^Admin^You have successfully created your account. You can click ask question to post your first question.";
                    notify.UserName = stu.Username;
                    notify.postedTime = DateTime.Now;
                    _dbContext.notifications.Add(notify);

                    Notifications notify2 = new Notifications();
                    notify2.ID = Guid.NewGuid();
                    notify2.isRead = false;
                    notify2.Message = "/Profiles/default/admin.png^Admin^We now have Arabic Language support as well.";
                    notify2.UserName = stu.Username;
                    notify2.postedTime = DateTime.Now;
                    _dbContext.notifications.Add(notify2);
                    _dbContext.SaveChanges();

                    // 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 RedirectToAction("Index", "Students");
                }
                else {

                    var userE = _dbContext.Users.Where(c => c.Email == model.Email).FirstOrDefault();
                    var userU = _dbContext.Users.Where(c => c.UserName == model.Username).FirstOrDefault();
                    if (userE != null)
                        ModelState.AddModelError("", "Email already exists.");
                    if (userU != null)
                        ModelState.AddModelError("", "Username already exists.");
                    ViewBag.error = "registerS";
                    return View("../Home/Index", model);
                }
            }

            // If we got this far, something failed, redisplay form
            // return View(model);
            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 7
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser
                {
                    UserName = model.Username,
                    Email = model.Email,

                };
               
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (model.SignupAS == "1")
                    {
                        var roleresult = UserManager.AddToRole(user.Id, Status.Student);
                        Student stu = new Student();
                        stu.StudentID = new Guid(user.Id);
                        stu.DateCreated = DateTime.Today;
                        Random rnd = new Random();
                        int filename = rnd.Next(1, 4);
                        stu.ProfileImage = "/Profiles/default/" + filename + ".png";
                        stu.Username = user.UserName;
                        _dbContext.Students.Add(stu);
                        _dbContext.SaveChanges();

                    }
                    else
                    {
                        var roleresult = UserManager.AddToRole(user.Id, Status.Tutor);
                        Tutor tutor = new Tutor();
                        tutor.DateOfBirth = DateTime.Today;
                        tutor.TutorID = new Guid(user.Id);
                        tutor.DateCreated = DateTime.Today;
                        tutor.IsCompletedProfile = false;
                        tutor.Username = user.UserName;
                        Random rnd = new Random();
                        int filename = rnd.Next(1, 4);
                        tutor.ProfileImage = "/Profiles/default/" + filename + ".png";
                        _dbContext.Tutors.Add(tutor);
                        _dbContext.SaveChanges();
                    }


                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }