コード例 #1
0
        public IActionResult Create(TeacherViewModel teacherViewModel)
        {
            var teacher = _mapper.Map <Teacher>(teacherViewModel);

            if (ModelState.IsValid)
            {
                try
                {
                    if (_teacherRepository.Add(teacher))
                    {
                        ViewBag.Message = "Teacher Saved succesfully";
                        ModelState.Clear();
                    }
                    else
                    {
                        ViewBag.Message = "Teacher Save failed";
                    }
                }
                catch (Exception e)
                {
                    ViewBag.TeacherExistMessage = e.Message;
                }
            }
            ViewBag.DepartmentId  = new SelectList(_departmentManager.GetAll(), "DepartmentId", "DepartmentName");
            ViewBag.DesignationId = new SelectList(_designationRepository.GetAll(), "DesignationId", "DesignationName");
            return(View());
        }
コード例 #2
0
        public IActionResult Create(TeacherViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Sections = _schoolServices.ListOfSections().ToList();
                return(View(viewModel));
            }


            string uniqueFileName = null;

            if (viewModel.Photo != null)
            {
                string uploadsFolder = Path.Combine(_hostingEnviroment.WebRootPath, "images", "teachers");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + viewModel.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                viewModel.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
            }
            IPositionStrategy strategy = new PositionStrategy();
            string            name     = strategy.CreatePosition(viewModel.SectionId);
            var      sectionName       = _schoolServices.GetSection((int)viewModel.SectionId).Name;
            Teacher  teacher           = _factory.Create(viewModel);
            Position position          = _positionFactory.GetPosition(name);

            teacher.Position  = position;
            teacher.PhotoPath = uniqueFileName;
            _repository.Add(teacher);
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <MessageModel <string> > Post([FromBody] Teacher Teacher)
        {
            var data = new MessageModel <string>();

            Teacher.Password = MD5Helper.MD5Encrypt32(Teacher.Account);
            var id = await _iTeacherRepository.Add(Teacher);

            data.success = id > 0;
            if (data.success)
            {
                List <CCT> cCTs = (from item in Teacher.clazzIds
                                   select new CCT
                {
                    IsDeleted = false,
                    clazzid = item,
                    courseid = Teacher.courseId,
                    teacherid = id,
                    gradeid = Teacher.gradeId,
                }).ToList();

                var newDataSave = await _iCCTRepository.Add(cCTs);

                data.response = id.ObjToString();
                data.msg      = "添加成功";
            }

            return(data);
        }
コード例 #4
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                if (Photo != null)
                {
                    if (Teacher.Photopath != null)
                    {
                        string filePath = Path.Combine(webHostEnvironment.WebRootPath, "images", Teacher.Photopath);
                        System.IO.File.Delete(filePath);
                    }

                    Teacher.Photopath = ProcessUploadedFile();
                }

                if (Teacher.ID > 0)
                {
                    Teacher = teacherRepository.Update(Teacher);
                }

                else
                {
                    Teacher = teacherRepository.Add(Teacher);
                }

                return(RedirectToPage("Index"));
            }

            return(Page());
        } //Allows the user to add or update the teacher account once it finishes it wil redirect to the home page
コード例 #5
0
        public async Task <IActionResult> AddTeacher([FromBody] TeacherDTO teacher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid input"));
            }

            if (teacher.age < 1)
            {
                return(BadRequest("Invalid input"));
            }

            Teacher newTeacher = new Teacher()
            {
                forename = teacher.forename,
                surname  = teacher.surname,
                age      = teacher.age
            };

            if (_teacherRepository.CheckIfExists(newTeacher))
            {
                return(Conflict("Teacher already exists"));
            }

            bool created = await _teacherRepository.Add(newTeacher);

            if (created)
            {
                return(Created("", newTeacher));
            }

            return(Conflict());
        }
コード例 #6
0
ファイル: TeacherController.cs プロジェクト: meow123321/SELab
 public IActionResult Create(Teacher teacher)
 {
     if (ModelState.IsValid)
     {
         teacherRepository.Add(teacher);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #7
0
        public async Task <IActionResult> CreateTeacher(TeacherDto teacherDto)
        {
            var teacher = _mapper.Map <Student>(teacherDto);

            _repo.Add(teacher);
            await _repo.SaveAll();

            return(Ok());
        }
コード例 #8
0
        public async Task <ActionResult> Post([FromBody] Teacher teacher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var teacherCreated = await _teacherRepository.Add(teacher);

            return(CreatedAtAction(nameof(Get), new { id = teacherCreated.Id }, teacherCreated));
        }
コード例 #9
0
ファイル: TeacherService.cs プロジェクト: gstvudia/MyCollege
        public Teacher Add(Teacher newTeacher)
        {
            if (_teacherRepository.GetByName(newTeacher.Name) != null)
            {
                return(null);
            }
            var created = _teacherRepository.Add(newTeacher);

            return(created);
        }
コード例 #10
0
        public async Task <IActionResult> PostTeacher([FromBody] Teacher teacher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _teacherRepository.Add(teacher);

            return(CreatedAtAction("GetTeacher", new { id = teacher.Id }, teacher));
        }
コード例 #11
0
        public void Handle(TeacherAddCommand message)
        {
            var teacher = new Domain.Course.Teacher(message.Id, message.Name, message.Email);

            _teacherRepository.Add(teacher);

            if (!Commit())
            {
                return;
            }

            _bus.RaiseEvent(new TeacherAddEvent(teacher.Name, teacher.Email));
        }
コード例 #12
0
        public IActionResult Post([FromBody] Teacher teacher)
        {
            if (teacher == null)
            {
                return(BadRequest());
            }
            int retVal = _teacherRepository.Add(teacher);

            if (retVal > 0)
            {
                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #13
0
        public IActionResult AddTeacher(TeacherViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool success = teacherRepository.Add(model);

                if (success)
                {
                    teacherRepository.Save();
                    return(RedirectToAction("TeacherManagement"));
                }

                ModelState.AddModelError("", "등록 실패");
            }

            return(View(model));
        }
コード例 #14
0
        public ActionResult Create(Teacher model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    WebSecurity.CreateUserAndAccount(model.ID, model.ID);
                    Roles.AddUserToRole(model.ID, "teacher");

                    teacherRepository.Add(model);
                    TempData["message"] = string.Format("Thêm giáo viên {0} thành công", model.FullName);
                    return(RedirectToIndex());
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", AccountController.ErrorCodeToString(e.StatusCode));
                }
            }
            return(View(model));
        }
コード例 #15
0
        public void Execute()
        {
            var newTeacher = new Teacher();

            Console.WriteLine(Strings.EnterTeachersFirtsName);
            newTeacher.FirstName = Console.ReadLine();
            Console.WriteLine(Strings.EnterTeachersLastName);
            newTeacher.LastName = Console.ReadLine();
            Console.WriteLine(Strings.EnterTeachersAge);
            int age;

            while (!int.TryParse(Console.ReadLine(), out age))
            {
                Console.WriteLine(Strings.InvalidAgeValue);
            }

            newTeacher.Age = age;

            _repository.Add(newTeacher);
            _repository.SaveChanges();
        }
コード例 #16
0
        public IActionResult Create(TeacherViewModel viewTeacher, int[] selectedCourses)
        {
            if (!ModelState.IsValid)
            {
                ViewData["error"] = $"There was a problem creating {viewTeacher.FullName}. Please try again.";
                return(View(nameof(Create), viewTeacher));
            }

            Teacher teacher = _mapper.Map <Teacher>(viewTeacher);

            foreach (var course in selectedCourses)
            {
                var crs = (_courseRepository.GetById(course));
                teacher.Courses.Add(crs);
            }

            _userRepository.Add(teacher);
            _userRepository.Save();

            ViewData["success"] = $"{viewTeacher.FullName} successfuly created.";
            return(RedirectToAction(nameof(Index)));
        }
コード例 #17
0
 public bool Add(TeacherEntity entity)
 {
     _teacherRepository.Add(entity);
     return(true);
 }
コード例 #18
0
 public void AddTeacher(Teacher teacher)
 {
     _teacherRepository.Add(teacher);
 }
コード例 #19
0
 public Teacher AddNewTeacher(Teacher teacher)
 {
     return(_teacherRepository.Add(teacher));
 }
コード例 #20
0
 public IActionResult Create(Teacher teacher)
 {
     ViewBag.CourseID = db2.GetAll();
     db1.Add(teacher);
     return(RedirectToAction("Index"));
 }
コード例 #21
0
 public bool Add(Teacher entity)
 {
     return(_repository.Add(entity));
 }
コード例 #22
0
 public Model.Teacher Add(Model.Teacher entity)
 {
     return(tea.Add(entity));
 }
コード例 #23
0
        public async Task <TeacherResponse> AddTeacher(Teacher entity)
        {
            var data = await _teacherRepository.Add(entity);

            return(data.toTeacherResponse());
        }
コード例 #24
0
 public Teacher Add(Teacher teacher)
 {
     return(_repository.Add(teacher));
 }
コード例 #25
0
 protected override async Task ExecuteCommandDataBase(Teacher entity) => await repository.Add(entity);
コード例 #26
0
 public void AddTeacher(params Teacher[] teachers)
 {
     _teacherRepository.Add(teachers);
 }
コード例 #27
0
 public void AddTeacher(TeacherDto teacherDto)
 {
     _teacherRepository.Add(_mapper.Map <Teacher>(teacherDto));
     _teacherRepository.SaveChanges();
 }