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()); }
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")); }
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); }
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
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()); }
public IActionResult Create(Teacher teacher) { if (ModelState.IsValid) { teacherRepository.Add(teacher); return(RedirectToAction("Index")); } return(View()); }
public async Task <IActionResult> CreateTeacher(TeacherDto teacherDto) { var teacher = _mapper.Map <Student>(teacherDto); _repo.Add(teacher); await _repo.SaveAll(); return(Ok()); }
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)); }
public Teacher Add(Teacher newTeacher) { if (_teacherRepository.GetByName(newTeacher.Name) != null) { return(null); } var created = _teacherRepository.Add(newTeacher); return(created); }
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)); }
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)); }
public IActionResult Post([FromBody] Teacher teacher) { if (teacher == null) { return(BadRequest()); } int retVal = _teacherRepository.Add(teacher); if (retVal > 0) { return(Ok()); } else { return(NotFound()); } }
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)); }
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)); }
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(); }
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))); }
public bool Add(TeacherEntity entity) { _teacherRepository.Add(entity); return(true); }
public void AddTeacher(Teacher teacher) { _teacherRepository.Add(teacher); }
public Teacher AddNewTeacher(Teacher teacher) { return(_teacherRepository.Add(teacher)); }
public IActionResult Create(Teacher teacher) { ViewBag.CourseID = db2.GetAll(); db1.Add(teacher); return(RedirectToAction("Index")); }
public bool Add(Teacher entity) { return(_repository.Add(entity)); }
public Model.Teacher Add(Model.Teacher entity) { return(tea.Add(entity)); }
public async Task <TeacherResponse> AddTeacher(Teacher entity) { var data = await _teacherRepository.Add(entity); return(data.toTeacherResponse()); }
public Teacher Add(Teacher teacher) { return(_repository.Add(teacher)); }
protected override async Task ExecuteCommandDataBase(Teacher entity) => await repository.Add(entity);
public void AddTeacher(params Teacher[] teachers) { _teacherRepository.Add(teachers); }
public void AddTeacher(TeacherDto teacherDto) { _teacherRepository.Add(_mapper.Map <Teacher>(teacherDto)); _teacherRepository.SaveChanges(); }