Exemple #1
0
        public async Task <IActionResult> Create(TeacherFormViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(model);

                Teacher teacher = new Teacher
                {
                    FirstName      = model.FirstName,
                    LastName       = model.LastName,
                    Degree         = model.Degree,
                    AcademicRank   = model.AcademicRank,
                    OfficeNumber   = model.OfficeNumber,
                    HireDate       = model.HireDate,
                    ProfilePicture = uniqueFileName,
                    Courses_first  = model.Courses_first,
                    Courses_second = model.Courses_second
                };

                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var teacher = await _context.Teacher.FindAsync(id);

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

            TeacherFormViewModel vm = new TeacherFormViewModel
            {
                Id             = teacher.Id,
                FirstName      = teacher.FirstName,
                LastName       = teacher.LastName,
                Degree         = teacher.Degree,
                AcademicRank   = teacher.AcademicRank,
                OfficeNumber   = teacher.OfficeNumber,
                HireDate       = teacher.HireDate,
                Courses_first  = teacher.Courses_first,
                Courses_second = teacher.Courses_second
            };

            return(View(vm));
        }
        public IActionResult Save(Teacher teacher)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new TeacherFormViewModel
                {
                    Teacher = teacher
                };
                return(View("TeacherForm", viewModel));
            }

            if (teacher.Id == 0)
            {
                var sqlTeacherList = new List <Teacher>();
                sqlTeacherList = LoadTeachers();

                if (!sqlTeacherList.Any(x => x.FirstName == teacher.FirstName && x.LastName == teacher.LastName))
                {
                    InsertTeacher(teacher);
                }
                else
                {
                    return(RedirectToAction("Index", "Teachers"));
                }
            }
            else
            {
                UpdateTeacher(teacher);
            }

            return(RedirectToAction("Index", "Teachers"));
        }
        public IActionResult Add()
        {
            var teacher   = new Teacher();
            var viewModel = new TeacherFormViewModel
            {
                Teacher = teacher
            };

            return(View("TeacherForm", viewModel));
        }
        public ActionResult New()
        {
            var departments      = _context.Departments.ToList();
            var teacherViewModel = new TeacherFormViewModel()
            {
                Departments = departments
            };

            return(View("TeacherForm", teacherViewModel));
        }
Exemple #6
0
        public ActionResult New()
        {
            var viewModel = new TeacherFormViewModel
            {
                Designations = _context.Designations.ToList(),
                Departments  = _context.Departments.ToList()
            };

            return(View(viewModel));
        }
Exemple #7
0
        public ActionResult RegisterTeacher()
        {
            var viewModel = new TeacherFormViewModel()
            {
                Specializations = _unitOfWork.Specializations.GetSpecializations()
                                  // Teachers = _teacherRepository.GetDectors()
            };

            return(View("TeacherForm", viewModel));
        }
        public IActionResult Edit(int id)
        {
            var teacher = LoadTeacher(id);

            var viewModel = new TeacherFormViewModel
            {
                Teacher = teacher
            };

            return(View("TeacherForm", viewModel));
        }
        public ActionResult Edit(int id)
        {
            var teacher = _context.Teachers.SingleOrDefault(c => c.ID == id);

            if (teacher == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new TeacherFormViewModel(teacher);

            return(View("TeacherForm", viewModel));
        }
Exemple #10
0
        public ActionResult Save(Teacher teacher)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new TeacherFormViewModel
                {
                    Name            = teacher.Name,
                    Address         = teacher.Address,
                    Email           = teacher.Email,
                    ContactNo       = teacher.ContactNo,
                    DepartmentId    = teacher.DepartmentId,
                    DesignationId   = teacher.DesignationId,
                    Designations    = _context.Designations.ToList(),
                    Departments     = _context.Departments.ToList(),
                    CreditToBeTaken = teacher.CreditToBeTaken
                };

                return(View("New", viewModel));
            }


            //IsUnique Cheack
            var teachers = _context.Teachers.Where(t => t.Email == teacher.Email).ToList();

            if (teachers.Count != 0)
            {
                var viewModel = new TeacherFormViewModel
                {
                    Name            = teacher.Name,
                    Address         = teacher.Address,
                    Email           = teacher.Email,
                    ContactNo       = teacher.ContactNo,
                    DepartmentId    = teacher.DepartmentId,
                    DesignationId   = teacher.DesignationId,
                    Designations    = _context.Designations.ToList(),
                    Departments     = _context.Departments.ToList(),
                    CreditToBeTaken = teacher.CreditToBeTaken,
                    ErrorMessage    = "This email address has already been taken"
                };

                return(View("New", viewModel));
            }
            //IsUnique Check end



            _context.Teachers.Add(teacher);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Teachers"));
        }
Exemple #11
0
        private string UploadedFile(TeacherFormViewModel model)
        {
            string uniqueFileName = null;

            if (model.ProfilePicture != null)
            {
                string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.ProfilePicture.FileName);
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.ProfilePicture.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
        public ActionResult Edit(int id)
        {
            var teacher = _context.Teachers.SingleOrDefault(c => c.TeacherId == id);

            if (teacher == null)
            {
                return(HttpNotFound());
            }
            var teacherViewModel = new TeacherFormViewModel()
            {
                Teacher     = teacher,
                Departments = _context.Departments.ToList()
            };

            return(View("TeacherForm", teacherViewModel));
        }
Exemple #13
0
        public async Task <IActionResult> Edit(int id, TeacherFormViewModel vm)
        {
            if (id != vm.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string uniqueFileName = UploadedFile(vm);

                    Teacher teacher = new Teacher
                    {
                        Id             = vm.Id,
                        FirstName      = vm.FirstName,
                        LastName       = vm.LastName,
                        ProfilePicture = uniqueFileName,
                        Degree         = vm.Degree,
                        AcademicRank   = vm.AcademicRank,
                        OfficeNumber   = vm.OfficeNumber,
                        HireDate       = vm.HireDate,
                        Courses_first  = vm.Courses_first,
                        Courses_second = vm.Courses_second
                    };

                    _context.Update(teacher);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TeacherExists(vm.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm));
        }
        public ActionResult Edit(TeacherFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Specializations = _unitOfWork.Specializations.GetSpecializations();
                return(View(viewModel));
            }

            var teacherInDb = _unitOfWork.Teachers.GetTeacher(viewModel.Id);

            teacherInDb.Id               = viewModel.Id;
            teacherInDb.Name             = viewModel.Name;
            teacherInDb.Phone            = viewModel.Phone;
            teacherInDb.Address          = viewModel.Address;
            teacherInDb.IsAvailable      = viewModel.IsAvailable;
            teacherInDb.SpecializationId = viewModel.Specialization;

            _unitOfWork.Complete();

            return(RedirectToAction("Details", new { id = viewModel.Id }));
        }
        public ActionResult Save(Teacher teacher)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new TeacherFormViewModel(teacher);

                return(View("TeacherForm", viewModel));
            }

            if (teacher.ID == 0)
            {
                _context.Teachers.Add(teacher);
            }
            else
            {
                var teacherInDb = _context.Teachers.Single(c => c.ID == teacher.ID);
                teacherInDb.Name = teacher.Name;
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", "Teachers"));
        }
        public ActionResult Edit(int id)
        {
            var teacher = _unitOfWork.Teachers.GetTeacher(id);

            if (teacher == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new TeacherFormViewModel()
            {
                Id              = teacher.Id,
                Name            = teacher.Name,
                Phone           = teacher.Phone,
                Address         = teacher.Address,
                IsAvailable     = teacher.IsAvailable,
                Specialization  = teacher.SpecializationId,
                Specializations = _unitOfWork.Specializations.GetSpecializations()
            };

            return(View(viewModel));
        }
Exemple #17
0
        public async Task <ActionResult> RegisterTeacher(TeacherFormViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = viewModel.RegisterViewModel.Email,
                    Email    = viewModel.RegisterViewModel.Email,
                    IsActive = true
                };
                var result = await UserManager.CreateAsync(user, viewModel.RegisterViewModel.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, RoleName.TeacherRoleName);


                    Teacher teacher = new Teacher()
                    {
                        Name             = viewModel.Name,
                        Phone            = viewModel.Phone,
                        Address          = viewModel.Address,
                        IsAvailable      = true,
                        SpecializationId = viewModel.Specialization,
                        PhysicianId      = user.Id
                    };
                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, teacher.Name));
                    _unitOfWork.Teachers.Add(teacher);
                    _unitOfWork.Complete();
                    return(RedirectToAction("Index", "Teachers"));
                }

                this.AddErrors(result);
            }

            viewModel.Specializations = _unitOfWork.Specializations.GetSpecializations();

            // If we got this far, something failed
            return(View("TeacherForm", viewModel));
        }
        public ActionResult Create()
        {
            var viewModel = new TeacherFormViewModel();

            return(View("TeacherForm", viewModel));
        }