Esempio n. 1
0
        public async Task <ActionResult> AssignTeacher(AssignTeacherViewModel userViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = userViewModel.Email,
                    Email    = userViewModel.Email,
                };

                var adminresult = await UserManager.CreateAsync(user, userViewModel.Password);

                //Add User to the selected Roles
                if (adminresult.Succeeded)
                {
                    UserManager.AddToRoles(user.Id, "Teacher");
                }
                else
                {
                    ModelState.AddModelError("", adminresult.Errors.First());
                    ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
                    return(View());
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
            return(View());
        }
Esempio n. 2
0
        public ActionResult AssignTeacher(AssignTeacherViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TeacherCourse tc = new TeacherCourse
                    {
                        TeacherId = model.TeacherId,
                        CourseId  = model.CourseId,
                        Year      = DateTime.Now.Year.ToString()
                    };
                    context.TeacherCourses.Add(tc);
                    context.SaveChanges();

                    TempData["SuccessMessage"] = "Teacher has been assigned.";
                }
                catch (Exception ex)
                {
                    TempData["ErrorMessage"] = ex.Message;
                }
            }

            return(RedirectToAction("Teachers"));
        }
        public ActionResult viewCourseStatics()
        {
            var model = new AssignTeacherViewModel();

            var result = courseTeacherDAL.CourseGetAll().Select(c => new { DepartmentId = c.DepartmentId, DepartmentName = c.Department.DepartmentName }).Distinct().ToList();

            model.DepartmentSelectListItemsViewCourseStatics = result.Select(c => new SelectListItem()
            {
                Value = c.DepartmentId.ToString(), Text = c.DepartmentName
            });
            return(View(model));
        }
        public ActionResult AssignTeacher()
        {
            var model = new AssignTeacherViewModel();

            model.DepartmentSelectListItems2 = courseTeacherDAL.TeacherGetAll().Select(c => new SelectListItem()
            {
                Value = c.DepartmentId.ToString(), Text = c.Department.DepartmentName
            });
            model.CoursetSelectListItems  = GetDefaultSelectListItem();
            model.TeachertSelectListItems = GetDefaultSelectListItem();
            model.TeachertInfoListItems   = GetTDefaultSelectListItem();
            return(View(model));
        }
Esempio n. 5
0
        public ActionResult Teachers()
        {
            AssignTeacherViewModel      model          = new AssignTeacherViewModel();
            IEnumerable <TeacherCourse> teacherCourses = context.TeacherCourses.ToList();
            IEnumerable <Teacher>       teachers       = context.Teachers.ToList();
            IEnumerable <Course>        courses        = context.Curriculum.ToList();

            model.TeacherCourses = teacherCourses;
            model.Teachers       = teachers;
            model.Courses        = courses;

            return(View(model));
        }
 public ActionResult ChangeSecTeacher(AssignTeacherViewModel model, int secId, int subId, int tId)
 {
     ViewBag.TeacherId = tId;
     ViewBag.SectionId = secId;
     ViewBag.SubjectId = subId;
     if (!ModelState.IsValid)
     {
         return(View());
     }
     try
     {
         HttpCookie conString   = Request.Cookies.Get("rwxgqlb");
         Teacher    prevTeacher = new Teacher(tId, Cryptography.Decrypt(conString.Value));
         Teacher    newTeacher  = new Teacher(model.TeacherId, Cryptography.Decrypt(conString.Value));
         foreach (var item in prevTeacher.GetAssignedSections())
         {
             if (item.Section.SectionId == secId && item.Subject.SubjectId == subId)
             {
                 if (!prevTeacher.RemoveSection(secId, subId))
                 {
                     return(RedirectToAction("ViewSection", new { id = secId, err = true }));
                 }
             }
         }
         try
         {
             if (newTeacher.AssignSection(secId, subId))
             {
                 return(RedirectToAction("ViewSection", new { id = secId, s = true }));
             }
             else
             {
                 return(RedirectToAction("ViewSection", new { id = secId, err = true }));
             }
         }
         catch (Exception ex)
         {
             ViewBag.SectionId = secId;
             ViewBag.SubjectId = subId;
             ModelState.AddModelError(string.Empty, ex.Message);
             return(View());
         }
     }
     catch (Exception ex)
     {
         return(Content(ex.Message));
     }
 }
 public ActionResult AssignSecTeacher(AssignTeacherViewModel model, int secId, int subId)
 {
     if (!ModelState.IsValid)
     {
         ViewBag.SectionId = secId;
         ViewBag.SubjectId = subId;
         return(View());
     }
     try
     {
         HttpCookie conString = Request.Cookies.Get("rwxgqlb");
         Teacher    t         = new Teacher(model.TeacherId, Cryptography.Decrypt(conString.Value));
         try
         {
             if (t.AssignSection(secId, subId))
             {
                 return(RedirectToAction("ViewSection", new { id = secId, s = true }));
             }
             else
             {
                 return(RedirectToAction("ViewSection", new { id = secId, err = true }));
             }
         }
         catch (Exception ex)
         {
             ViewBag.SectionId = secId;
             ViewBag.SubjectId = subId;
             ModelState.AddModelError(string.Empty, ex.Message);
             return(View());
         }
     }
     catch (Exception ex)
     {
         return(Content(ex.Message));
     }
 }
        public ActionResult AssignTeacher(AssignTeacher assignTeacher)
        {
            //var message = "";

            if (ModelState.IsValid)
            {
                bool isSaved = courseTeacherManager.Add(assignTeacher);
                if (isSaved)
                {
                    ViewBag.SMessage = "Assign Teacher Successfully!";
                    ModelState.Clear();
                }
                else
                {
                    ViewBag.EMessage = "This Course Already Assigned";
                }
            }
            else
            {
                ViewBag.EMessage = "Failed";
            }
            var model = new AssignTeacherViewModel();

            model.DepartmentSelectListItems2 = courseTeacherDAL.TeacherGetAll().Select(c => new SelectListItem()
            {
                Value = c.DepartmentId.ToString(), Text = c.Department.DepartmentName
            });
            model.CoursetSelectListItems = courseTeacherDAL.CourseGetAll().Select(c => new SelectListItem()
            {
                Value = c.CourseId.ToString(), Text = c.CourseCode
            });
            model.TeachertSelectListItems = GetDefaultSelectListItem();
            model.TeachertInfoListItems   = GetTDefaultSelectListItem();
            //ViewBag.EMessage = message;
            return(View(model));
        }