// GET: Instructors
        public async Task <IActionResult> Index(int?id, int?courseID)
        {
            InstructorViewModel viewModel = new InstructorViewModel();

            viewModel.Instructors = await _context.Instructors
                                    .Include(i => i.OfficeAssignment)
                                    .Include(i => i.CourseAssignments)
                                    .ThenInclude(i => i.Course)
                                    .ThenInclude(i => i.Enrollments)
                                    .ThenInclude(i => i.Student)
                                    .Include(i => i.CourseAssignments)
                                    .ThenInclude(i => i.Course)
                                    .ThenInclude(i => i.Department)
                                    .AsNoTracking()
                                    .OrderBy(i => i.LastName)
                                    .ToListAsync();

            if (id.HasValue)
            {
                ViewData["InstructorID"] = id.Value;
                Instructor instructor = viewModel.Instructors.FirstOrDefault(
                    i => i.Id == id.Value);
                viewModel.Courses = instructor.CourseAssignments.Select(s => s.Course).ToList();
            }

            if (courseID.HasValue)
            {
                ViewData["CourseID"]  = courseID.Value;
                viewModel.Enrollments = viewModel.Courses.FirstOrDefault(
                    x => x.CourseId == courseID).Enrollments.ToList();
            }

            return(View(viewModel));
        }
        public ActionResult Index_Home()
        {
            //Neu bam vao mon dang day, moi ra index
            //Tim instructor da dang nhạp vao

            string     Username             = this.HttpContext.User.Identity.Name;
            User       User                 = AccBO.GetUserByUsername(Username);
            Instructor AuthorizedInstructor = InsBO.GetInstructorByUserID(User.UserID);

            //Nhung mon ma instructor nay dang day, sau nay phai check status
            var RollCalls = RollBO.GetInstructorCurrentRollCalls(AuthorizedInstructor.InstructorID);

            //Mon dang day vao thoi diem dang nhap
            RollCall CurrentRollCall = null;
            TimeSpan CurrentTime     = DateTime.Now.TimeOfDay;

            if (RollCalls.Count() > 0)
            {
                CurrentRollCall = RollCalls.FirstOrDefault(r => r.StartTime <= CurrentTime && r.EndTime >= CurrentTime);
            }

            InstructorViewModel model = new InstructorViewModel();

            model.AuthorizedInstructor = AuthorizedInstructor;
            model.CurrentRollCall      = CurrentRollCall;
            model.TeachingRollCall     = RollCalls;
            return(View(model));
        }
        public IActionResult Create(InstructorViewModel viewModel, [FromServices] CreateInstructor command)
        {
            if (ModelState.IsValid)
            {
                command.Instructor = mapper.Map <Instructor>(viewModel);
                //only look for courses if instructor choose to be assigned one
                if (viewModel.Filters != null)
                {
                    IList <Filter> filter           = viewModel.Filters.ToList();
                    IList <Course> courses          = queryDb.Courses.ToList();
                    IList <Course> coursesToBeAdded = new List <Course>();
                    foreach (var item in filter)
                    {
                        if (item.Selected)
                        {
                            coursesToBeAdded.Add(courses.Where(i => i.CourseId == item.Id).Single());
                        }
                    }
                    command.Courses = coursesToBeAdded;
                }

                command.Run();
                if (command.Status)
                {
                    return(RedirectToAction("Index", "Instructor"));
                }
                else
                {
                    return(RedirectToAction("Error", "Instructor"));
                }
            }
            return(View());
        }
        public ActionResult AddInstructor(InstructorViewModel instructor)
        {
            if (!ValidState(instructor.Instructors.username))
            {
                var data2 = ShowAllInstructor();
                data2.extra = "Username Already Exists!";
                return(RedirectToAction("Index", data2));
            }
            var data1 = ShowAllInstructor();

            data1.extra = "Invalid State";
            if (!ModelState.IsValid)
            {
                //var errors = ModelState.Values.All(modelState => modelState.Errors.Count == 0);

                return(RedirectToAction("Index", data1));
            }

            var data = ShowAllInstructor();

            data.extra = "Instructor Not Added!";
            //Encrypted Passwod
            SHA256 mySHA256 = SHA256Managed.Create();

            byte[] hashvalue;
            byte[] byteArray = Encoding.ASCII.GetBytes((string)instructor.Instructors.password);
            hashvalue = mySHA256.ComputeHash(byteArray);
            instructor.Instructors.password = Encoding.ASCII.GetString(hashvalue);

            byte[] hashvalue1;
            byte[] byteArray1 = Encoding.ASCII.GetBytes((string)instructor.repassword);
            hashvalue1            = mySHA256.ComputeHash(byteArray1);
            instructor.repassword = Encoding.ASCII.GetString(hashvalue1);

            if (instructor.Instructors.password == instructor.repassword)
            {
                if (instructor.Instructors.id == 0 || instructor.Instructors.id == null) //Adding Instructor
                {
                    //Before Image
                    HttpPostedFileBase photo = Request.Files["image"];
                    string             destinationDirectory  = @"C:\Users\Mujeeb Arshad\Documents\Visual Studio 2013\Projects\Attendance\Attendance\Content\assets\img\";
                    string             destinationDirectory1 = destinationDirectory + photo.FileName;
                    photo.SaveAs(destinationDirectory1);
                    if (System.IO.File.Exists(destinationDirectory + instructor.Instructors.username + ".jpg"))
                    {
                        System.IO.File.Delete(destinationDirectory + instructor.Instructors.username + ".jpg");
                    }
                    System.IO.File.Move(destinationDirectory1, destinationDirectory + instructor.Instructors.username + ".jpg");
                    instructor.Instructors.image_path = "../../Content/assets/img/" + instructor.Instructors.username + ".jpg";
                    //After Image

                    _context.Instructors.Add(instructor.Instructors);
                }

                _context.SaveChanges();
                data       = ShowAllInstructor();
                data.extra = "Instructor has been Added!";
            }
            return(RedirectToAction("Index", data));
        }
        public ActionResult Delete(int id)
        {
            if (Session["UserName"] != null)
            {
                var instructor = _context.Instructors.SingleOrDefault(c => c.id == id);
                if (instructor == null)
                {
                    return(HttpNotFound());
                }

                _context.Instructors.Attach(instructor);
                _context.Instructors.Remove(instructor);
                _context.SaveChanges();

                var data = new InstructorViewModel
                {
                };
                return(RedirectToAction("Index", data));
            }
            else
            {
                var data = new User()
                {
                    userType = "Invalid Login"
                };
                return(RedirectToAction("Index", "Home", data));
            }
        }
Beispiel #6
0
        public ActionResult Delete(InstructorViewModel model)
        {
            try
            {
                var response = _instructorLogic.Delete(model.Id);;
                if (response.IsError == true)
                {
                    foreach (var error in response.ErrorCodes)
                    {
                        ModelState.AddModelError(string.Empty, error);
                    }

                    var item = _instructorLogic.GetById(model.Id);
                    InstructorViewModel instructor = new InstructorViewModel()
                    {
                        Id = item.Id, Address = item.Address, Area = item.Area, CityId = item.CityId, CityName = item.City.Title, DateOfBirth = item.DateOfBirth.ToString("dd-mm-yyyy"), Email = item.Email, Name = item.Name, PhoneNumber = item.PhoneNumber, PlaceOfBirth = item.PlaceOfBirth, StateId = item.StateId, StateName = item.State.Title
                    };
                    return(View(instructor));
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #7
0
        public IActionResult Instructor(InstructorViewModel model)
        {
            Validation <InstructorViewModel> instructorViewModel = new Validation <InstructorViewModel>();

            if (ModelState.IsValid)
            {
                if (model != null)
                {
                    instructorViewModel = ınstructorManager.Insert(model);

                    if (instructorViewModel.ErrorList.Count == 0)
                    {
                        _IRedisCacheService.GetAllRemove();
                        toastNotification.AddSuccessToastMessage("Eğitmen Ekleme İşlemi Başarılı");
                        return(RedirectToAction("Instructor"));
                    }
                    else
                    {
                        instructorViewModel.ErrorList.ForEach(x => toastNotification.AddAlertToastMessage(x));
                        return(RedirectToAction("Instructor"));
                    }
                }
                else
                {
                    toastNotification.AddWarningToastMessage("Eğitmen Ekleme İşlemi Sırasında Bir Hata Meydana Geldi!");
                    return(RedirectToAction("Instructor"));
                }
            }
            else
            {
                ModelState.Values.ToList().ForEach(x => x.Errors.ToList().ForEach(y => toastNotification.AddWarningToastMessage(y.ErrorMessage)));
                return(RedirectToAction("Instructor"));
            }
        }
Beispiel #8
0
        public async Task <IActionResult> Index(int?id, int?courseId)
        {
            var allInstructors = await _instructorRepository.InstructorsAsync();

            var model = new InstructorViewModel()
            {
                Instructors = allInstructors
            };

            if (id != null)
            {
                ViewData["InstructorId"] = id.Value;
                var instructor = model.Instructors.FirstOrDefault(x => x.InstructorId == id);
                if (instructor != null)
                {
                    model.Courses = instructor.CourseAssignments.Select(s => s.Course); //LinqPad kullanıldı.
                }
            }

            if (courseId != null)
            {
                ViewData["CourseId"] = courseId.Value;
                model.Enrollments    = model.Courses.FirstOrDefault(x => x.Id == courseId)?.Enrollments;
            }

            return(View(model));
        }
        public IActionResult Update(Guid id, [FromBody] InstructorViewModel item)
        {
            if (item == null || item.Id != id)
            {
                return(BadRequest());
            }

            var instructor = _context.Instructors.FirstOrDefault(t => t.Id == id);

            if (instructor == null)
            {
                return(NotFound());
            }

            //instructor.Id = item.;
            instructor.FirstName = item.FirstName;
            instructor.LastName  = item.LastName;
            instructor.State     = item.State;
            instructor.Suburb    = item.Suburb;
            instructor.Address   = item.Address;
            instructor.School    = item.School;
            instructor.Email     = item.Email;
            instructor.Phone     = item.Phone;
            instructor.Mobile    = item.Mobile;
            instructor.Info      = item.Info;
            instructor.Price     = item.Price;
            instructor.Language  = item.Language;


            _context.Instructors.Update(instructor);
            _context.SaveChanges();
            return(new NoContentResult());
        }
Beispiel #10
0
 public ActionResult Edit(InstructorViewModel model)
 {
     try
     {
         Instructor instructor = new Instructor()
         {
             Id = model.Id, Address = model.Address, Area = model.Area, CityId = model.CityId, DateOfBirth = DateTime.ParseExact(model.DateOfBirth, "mm-dd-yyyy", System.Globalization.CultureInfo.InvariantCulture), Email = model.Email, Name = model.Name, PhoneNumber = model.PhoneNumber, PlaceOfBirth = model.PlaceOfBirth, StateId = model.StateId
         };
         var response = _instructorLogic.Edit(instructor);
         if (response.IsError == true)
         {
             foreach (var item in response.ErrorCodes)
             {
                 ModelState.AddModelError(string.Empty, item);
             }
             PrepareSelectList(model.StateId, model.CityId);
             return(View(model));
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #11
0
        public async Task <IActionResult> EditPost(int?id, [Bind("FirstName", "LastName", "HireDate", "OfficeAssignmentViewModel")] InstructorViewModel instructorViewModel, string[] selectedCourses)
        {
            if (id == null)
            {
                NotFound();
            }

            var instructor = await _serviceInstructor.GetByIdAsync((int)id);

            instructor = instructor.UpdateInstructor(instructorViewModel.FirstName, instructorViewModel.LastName, instructorViewModel.HireDate, instructorViewModel.OfficeAssignmentViewModel.Location);

            if (await TryUpdateModelAsync(
                    instructor,
                    "Instructor",
                    i => i.FirstName, i => i.LastName, i => i.HireDate, i => i.OfficeAssignment))
            {
                if (string.IsNullOrWhiteSpace(instructor.OfficeAssignment?.Location))
                {
                    instructor.OfficeAssignment = null;
                }

                UpdateInstructorCourses(selectedCourses, instructor);

                await _serviceInstructor.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            UpdateInstructorCourses(selectedCourses, instructor);

            PopulateAssignedCourseData(instructorViewModel);

            return(View(instructorViewModel));
        }
        public ActionResult Delete(int id)
        {
            Instructor          instructor = db.Instructors.Find(id);
            InstructorViewModel model      = Mapper.Map <Instructor, InstructorViewModel>(instructor);

            return(View(model));
        }
        public IActionResult Create([FromBody] InstructorViewModel item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            var instructor = new Instructor
            {
                Id        = item.Id,
                FirstName = item.FirstName,
                LastName  = item.LastName,
                State     = item.State,
                Suburb    = item.Suburb,
                Address   = item.Address,
                School    = item.School,
                Email     = item.Email,
                Phone     = item.Phone,
                Mobile    = item.Mobile,
                Info      = item.Info,
                //ProfilePic = item.
                Price    = item.Price,
                Language = item.Language
            };

            _context.Instructors.Add(instructor);
            _context.SaveChanges();

            return(CreatedAtRoute("GetInstructor", new { id = instructor.Id }, instructor));
        }
        public IActionResult Index()
        {
            var viewModel = new InstructorViewModel();

            viewModel.Instructors = queryDb.Instructors.ToList();
            return(View(viewModel));
        }
        //This method fills a Filter[] with data about the courses.
        //Filter[] contains an Assigned Boolean which will tell the view whether or not the course is available for a instructor
        public Filter[] CheckBoxInitialization(InstructorViewModel viewModel)
        {
            int courseCount = viewModel.Courses.Count();//viewModel.Courses.Count();

            //int courseCount = queryDb.Courses.Count();
            Course[] course = new Course[courseCount];
            course = viewModel.Courses.ToArray();
            Filter[] filter = new Filter[courseCount];

            //Has to initialize every filter to avoid Non-instantiated object exception or whatever
            for (int i = 0; i < courseCount; i++)
            {
                filter[i] = new Filter();
            }
            //Now we can fill the Filter array with data which is used by the razor view
            for (int i = 0; i < courseCount; i++)
            {
                filter[i].Id       = course[i].CourseId;
                filter[i].Name     = course[i].Name;
                filter[i].Selected = false;
                if (course[i].InstructorId != null)
                {
                    filter[i].Assigned = true;
                }
                else
                {
                    filter[i].Assigned = false;
                }
            }
            return(filter);
        }
Beispiel #16
0
        public ActionResult Create(InstructorViewModel viewModel)
        {
            try
            {
                using (SqlConnection conn = Connection)
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = @"INSERT INTO Instructors
                ( FirstName, LastName, SlackHandle, CohortId, Specialty )
                VALUES
                ( @firstName, @lastName, @slackHandle, @cohortId, @specialty )";
                        cmd.Parameters.Add(new SqlParameter("@firstName", viewModel.instructor.FirstName));
                        cmd.Parameters.Add(new SqlParameter("@lastName", viewModel.instructor.LastName));
                        cmd.Parameters.Add(new SqlParameter("@slackHandle", viewModel.instructor.SlackHandle));
                        cmd.Parameters.Add(new SqlParameter("@cohortId", viewModel.instructor.CohortId));
                        cmd.Parameters.Add(new SqlParameter("@specialty", viewModel.instructor.Specialty));
                        cmd.ExecuteNonQuery();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
            }
            catch
            {
                return(View());
            }
        }
Beispiel #17
0
        private ActionResult SaveInstructor(int?id, InstructorViewModel formData)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var user        = new ApplicationUser {
                UserName = formData.Email, Email = formData.Email
            };
            var result     = userManager.Create(user, formData.Password);
            var userId     = user.Id;
            var instructor = Mapper.Map <Instructor>(formData);

            if (!id.HasValue)
            {
                var allInstructors = DbContext.InstructorDatabase.ToList();
                if (allInstructors.Count != 0)
                {
                    if (allInstructors.Any(p => p.Email == instructor.Email))
                    {
                        var instructorEmail = DbContext.InstructorDatabase.FirstOrDefault(p => p.Email == instructor.Email).Email;
                        return(RedirectToAction("EmailError"));
                    }
                }

                DbContext.InstructorDatabase.Add(instructor);
                DbContext.SaveChanges();

                if (!userManager.IsInRole(user.Id, "Instructor"))
                {
                    userManager.AddToRoleAsync(user.Id, "Instructor");
                }

                string code        = userManager.GenerateEmailConfirmationToken(user.Id);
                var    callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                userManager.SendEmailAsync(userId, "Notification",
                                           "You are registered as an Instructor. Your Current Password is 'Password-1'. Please change your password by clicking <a href=\"" + callbackUrl + "\">here</a>");

                return(RedirectToAction("Index"));
            }
            else
            {
                instructor = DbContext.InstructorDatabase.FirstOrDefault(p => p.Id == id);
                if (instructor == null)
                {
                    return(RedirectToAction(nameof(InstructorController.Index)));
                }
            }

            instructor.FirstName = formData.FirstName;
            instructor.LastName  = formData.LastName;
            instructor.Email     = formData.Email;
            instructor.Courses.Find(p => p.Id == formData.CourseId);
            DbContext.SaveChanges();

            return(RedirectToAction(nameof(InstructorController.Detail), new { id = instructor.Id }));
        }
Beispiel #18
0
        public IActionResult Create()
        {
            var instructorViewModel = new InstructorViewModel();

            PopulateAssignedCourseData(instructorViewModel);

            return(View());
        }
        public IActionResult Create()
        {
            var viewModel = new InstructorViewModel();

            viewModel.Courses = queryDb.Courses.ToList();
            viewModel.Filters = CheckBoxInitialization(viewModel);
            return(View(viewModel));
        }
Beispiel #20
0
        public IActionResult OnGet()
        {
            var emptyInstructor = new Instructor();

            Instructor = _mapper.Map <InstructorViewModel>(emptyInstructor);

            return(Page());
        }
Beispiel #21
0
        public ActionResult Instructor()
        {
            InstructorViewModel view_model = new InstructorViewModel
            {
                course_collection     = data_access.getAllCourse(),
                instructor_collection = data_access.getAllInstructor()
            };

            return(View(view_model));
        }
        public InstructorViewModel ShowAllInstructor()
        {
            var instructors = _context.Instructors.ToList();
            var viewModel   = new InstructorViewModel
            {
                Inst_list = instructors
            };

            return(viewModel);
        }
Beispiel #23
0
        // GET: Instructor/Details/5
        public ActionResult Details(int id)
        {
            var item = _instructorLogic.GetById(id);
            InstructorViewModel instructor = new InstructorViewModel()
            {
                Id = item.Id, Address = item.Address, Area = item.Area, CityId = item.CityId, CityName = item.City.Title, DateOfBirth = item.DateOfBirth.ToString("dd-mm-yyyy"), Email = item.Email, Name = item.Name, PhoneNumber = item.PhoneNumber, PlaceOfBirth = item.PlaceOfBirth, StateId = item.StateId, StateName = item.State.Title
            };

            return(View(instructor));
        }
Beispiel #24
0
        public ActionResult Add(InstructorViewModel model)
        {
            if (ModelState.IsValid)
            {
                //TODO logic

                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            Instructor = _mapper.Map <InstructorViewModel>(await _instructorRepository.GetInstructorWithChildrenAsync(id));

            if (Instructor == null)
            {
                return(NotFound());
            }

            return(Page());
        }
        public ActionResult Search(string username)
        {
            username = Request.Form["search"];
            var result = _context.Instructors.Where(c => c.username == username).ToList();
            var data   = new InstructorViewModel
            {
                Inst_list = result
            };

            return(View("Instructor", data));
        }
 public ActionResult Edit(InstructorViewModel model)
 {
     if (ModelState.IsValid)
     {
         Instructor instructor = Mapper.Map <InstructorViewModel, Instructor>(model);
         db.Entry(instructor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Beispiel #28
0
        public async Task UpdateAsync(InstructorViewModel instructor, string[] selectedCourses)
        {
            if (selectedCourses.Any())
            {
                var allCourses = new CourseMapper().ManyTo(_context.Courses);
                UpdateInstructorCourses(allCourses, selectedCourses, instructor);
            }

            _context.Instructors.Update(new InstructorMapper().SingleFrom(instructor));

            await _context.SaveChangesAsync();
        }
        public ActionResult Create(InstructorViewModel model)
        {
            if (ModelState.IsValid)
            {
                Instructor instructor = Mapper.Map <InstructorViewModel, Instructor>(model);
                db.Instructors.Add(instructor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public InstructorViewModel Get <U>(Expression <Func <Instructor, bool> > predicate, Expression <Func <Instructor, U> > includePredicate)
        {
            var instructor = _instructorRepository.Get(predicate, includePredicate);
            var vm         = new InstructorViewModel
            {
                Id          = instructor.Id,
                Name        = instructor.Name,
                Designation = instructor.Designation,
                Skill       = instructor.Skill
            };

            return(vm);
        }