public async Task <IActionResult> Add(CreateStudentModel model) { if (!ModelState.IsValid) { return(BadRequest(modelState: ModelState)); } if (_db.Students.Any(x => x.Username == model.Username)) { return(BadRequest(new { message = "duplicate user name" })); } var student = new Student() { FullName = model.FullName, Username = model.Username, Password = model.Password, SchoolId = model.SchoolId }; await _db.Students.AddAsync(student); await _db.SaveChangesAsync(); return(Ok()); }
public ActionResult Create(CreateStudentModel student) { if (ModelState.IsValid) { string uniqueFileName = ProcessImage(student); Student sd = new Student { Name = student.Name, DateOfBirth = student.DateOfBirth, Gender = student.Gender, PhoneNumber = student.PhoneNumber, Email = student.Email, Address = student.Address, MaritalStatus = student.MaritalStatus, HealthCondition = student.HealthCondition, Status = student.Status, AdmissionType = student.AdmissionType, Nationalty = student.Nationalty, NextOFKinName = student.NextOFKinName, NextOfKinAddress = student.NextOfKinAddress, NextOfKinNumber = student.NextOfKinNumber, Photo = uniqueFileName }; var add = _er.Add(sd); ViewBag.Message = "Data Inserted Successful"; return(RedirectToAction("Guarantor", new { id = sd.Id })); } return(View()); }
public ActionResult CreateStudent(CreateStudentModel student) { string expressSql = "addStudent2"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(expressSql, connection) { CommandType = System.Data.CommandType.StoredProcedure }; SqlParameter namePar = new SqlParameter // parameter for enter name { ParameterName = "@idGroup", Value = student.IdStudyGroup }; command.Parameters.Add(namePar); // add SqlParameter idStudPar = new SqlParameter // parameter for id { ParameterName = "@idEmpl", Value = student.IdEmployee }; command.Parameters.Add(idStudPar); var result = command.ExecuteNonQuery(); } return(RedirectToAction("Edit", new { id = student.IdStudyGroup })); }
public ActionResult CreateStudentAccount(CreateStudentModel model) { MakerLabDBDataContext db = new MakerLabDBDataContext(); db.add_student(model.IDno, model.Email, model.FirstName, model.LastName, model.ClassYear); return(RedirectToAction("Index", "Home")); }
public ActionResult Create() { CreateStudentModel crObj = new CreateStudentModel(); crObj.courseList = _context.Courses.ToList(); return(View(crObj)); }
private string ProcessUploadFile(CreateStudentModel viewobj) { string uniqueFileName = null; var files = HttpContext.Request.Form.Files; foreach (var image in files) { if (image != null && image.Length > 0) { var file = image; var uploadFile = Path.Combine(_hostingEnvironment.WebRootPath, "Images"); if (file.Length > 0) { var fileName = file.FileName; using (var fileStream = new FileStream(Path.Combine(uploadFile, fileName), FileMode.Create)) { file.CopyTo(fileStream); uniqueFileName = fileName; } } } } return(uniqueFileName); }
public IHttpActionResult CreateStudent(CreateStudentModel model) { IHttpActionResult httpActionResult; ErrorModel error = new ErrorModel(); if (string.IsNullOrEmpty(model.StudentName)) { error.Add("Họ tên là bắt buộc!"); } if (string.IsNullOrEmpty(model.StudentAddress)) { error.Add("Địa chỉ là bắt buộc!"); } if (error.Errors.Count == 0) { Student sv = new Student(); sv.StudentName = model.StudentName; sv.StudentAddress = model.StudentAddress; sv.StudentBirth = model.StudentBirth; sv.StudentId = model.StudentId; sv.Class = _db.Class.FirstOrDefault(x => x.Id == model.Class_Id); sv = this._db.Student.Add(sv); this._db.SaveChanges(); StudentModel viewModel = new StudentModel(sv); httpActionResult = Ok(viewModel); } else { httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, error); } return(httpActionResult); }
public async Task <IActionResult> CreateStudent([FromBody] CreateStudentModel createStudentModel) { CreateStudentDto createStudentDto = _mapper.Map <CreateStudentDto>(createStudentModel); await _studentService.CreateStudentAsync(createStudentDto); return(Ok()); }
public ActionResult NewStudent() { CreateStudentModel vm = new CreateStudentModel(); BuildingViewer viewer = new BuildingViewer(); vm.Building = viewer.GetAllBuildingname(); return(View(vm)); }
public void ShouldHaveErrorsIfModelNotValid() { var createStudentModel = new CreateStudentModel { FirstName = null, }; _validator.ShouldHaveValidationErrorFor(csm => csm.FirstName, createStudentModel); }
public void ShouldHaveErrorIfStudentAlreadyExists() { var createStudentModel = new CreateStudentModel { StudentUsi = 234 }; _validator.ShouldHaveValidationErrorFor(csm => csm.StudentUsi, createStudentModel); }
public async Task <ActionResult <Student> > Post(CreateStudentModel studentModel) { _logger.LogInfo("Student creation called"); var student = _mapper.Map <Student>(studentModel); await _studentService.Add(student); _logger.LogInfo("Student created successfully"); return(CreatedAtAction(nameof(Post), student)); }
public ActionResult AddOrEdit(CreateStudentModel viewObj) { var result = false; string uniqueFile = ProcessUploadFile(viewObj); Student studentObj = new Student(); studentObj.Name = viewObj.Name; studentObj.DoB = viewObj.DoB; studentObj.Email = viewObj.Email; studentObj.Phone = viewObj.Phone; studentObj.CourseFee = viewObj.CourseFee; studentObj.CourseID = viewObj.CourseID; //studentObj.ImageName = fileWithExtension; studentObj.ImageUrl = uniqueFile; //string fileServerPath = Path.Combine(Server.MapPath("~/Images/" + fileName + extension)); //viewObj.ImageFile.SaveAs(fileServerPath); if (ModelState.IsValid) { if (viewObj.StudentID == 0) { _repoObj.SaveStudent(studentObj); result = true; } else { studentObj.StudentID = viewObj.StudentID; _repoObj.UpdateStudent(studentObj); result = true; } } if (result) { return(RedirectToAction("Index")); } else { if (viewObj.StudentID == 0) { CreateStudentModel crObj = new CreateStudentModel(); crObj.courseList = _context.Courses.ToList(); return(View("Create", crObj)); } else { CreateStudentModel crObj = new CreateStudentModel(); crObj.courseList = _context.Courses.ToList(); return(View("Edit", crObj)); } } }
public async Task <Guid> CreateAsync(CreateStudentModel studentModel) { var studentEntity = new Student() { Name = studentModel.Name }; await this.studentRepository.AddAsync(studentEntity); this.eventSource.Handle(new StudentCreated(studentEntity.StudentId.ToString())); return(studentEntity.StudentId); }
public virtual ActionResult CreateStudent(CreateStudentModel createStudentModel) { if (!ModelState.IsValid) { return(View(createStudentModel)); } var student = new Student(); _enrollmentMapper.Map(createStudentModel, student); _repository.Add(student); _repository.Save(); return(RedirectToAction(MVC.Enrollment.EnterAcademicDetails(createStudentModel.StudentUsi.GetValueOrDefault()))); }
public ActionResult CreateStudent(CreateStudentModel formdata) { NewStudentDTO dto = new NewStudentDTO(); dto.StudentID = formdata.StudentID; dto.Firstname = formdata.FirstName; dto.Lastname = formdata.LastName; dto.Address = formdata.Address; dto.Buildingname = formdata.Buildingname; NewStudentCreator student_Creator = new NewStudentCreator(); student_Creator.CreateStudent(dto); return(RedirectToAction("AfterStudent", "Student")); }
public async Task <ActionResult> Create(CreateStudentModel student) { if (string.IsNullOrWhiteSpace(student.StudentName)) { return(View()); } var updatedCount = await _studentOrchestrator.CreateStudent(new Shared.ViewModels.StudentViewModel { StudentId = Guid.NewGuid(), StudentName = student.StudentName, Height = student.Height, Weight = student.Weight }); return(View()); }
public ActionResult CreateStudent(int IdGroup) { TeachersModel teach = GetTeacher(IdGroup); List <OrgModel> Orgs = GetOrg(teach.IdTeacher); int selectedIndex = Orgs.ElementAt(0).IdOrganization; List <EmployeeModel> Employee = GetEmployee(selectedIndex); CreateStudentModel createStudentModel = new CreateStudentModel { EmployeeList = GetStudentsOfGroup(IdGroup), IdStudyGroup = IdGroup, NameStudyGroup = GetGroup(IdGroup), NameTeacher = teach.NameTeacher, Organizations = new SelectList(Orgs, "IdOrganization", "NameOrganization"), Employee = new SelectList(Employee, "IdEmployee", "NameEmployee") }; return(View(createStudentModel)); }
public ActionResult CreateStudentAccount() { string email; if (User.Identity.Name.IndexOf("@rose-hulman.edu") > 0) { email = User.Identity.Name; } else { return(RedirectToAction("Index", "Home")); } var model = new CreateStudentModel() { Email = email }; return(View(model)); }
public ActionResult Delete(int id) { Student studentObj = _repoObj.GetStudentById(id); CreateStudentModel viewObj = new CreateStudentModel(); if (studentObj != null) { viewObj.StudentID = studentObj.StudentID; viewObj.Name = studentObj.Name; viewObj.DoB = studentObj.DoB; viewObj.Email = studentObj.Email; viewObj.Phone = studentObj.Phone; viewObj.CourseFee = studentObj.CourseFee; viewObj.CourseID = studentObj.CourseID; viewObj.ImageUrl = studentObj.ImageUrl; } return(View(viewObj)); }
public IActionResult AddStudent([ Bind(nameof(CreateStudentModel.Name), nameof(CreateStudentModel.Email), nameof(CreateStudentModel.Department))] CreateStudentModel model) { if (ModelState.IsValid) { try { model.Create(); return(RedirectToAction("Index")); } catch (Exception ex) { //model.Response = new ResponseModel("Book creation failed.", ResponseType.Failure); } } return(View(model)); }
private string ProcessImage(CreateStudentModel student) { string uniqueFileName = null; if (student.Photo != null && student.Photo.Count > 0) { foreach (IFormFile photo in student.Photo) { string uploadsFolder = Path.Combine(henv.WebRootPath, "img"); uniqueFileName = Guid.NewGuid().ToString() + " " + photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { photo.CopyTo(fileStream); } } } return(uniqueFileName); }
public bool AllFieldsExist(CreateStudentModel createStudentModel) { var studentFields = Browser.PageSource.Contains(createStudentModel.StudentUsi.ToString()) && Browser.PageSource.Contains(createStudentModel.FirstName) && Browser.PageSource.Contains(createStudentModel.LastName) && Browser.PageSource.Contains(createStudentModel.Sex.Humanize()) && Browser.PageSource.Contains(createStudentModel.BirthDate.GetValueOrDefault().ToShortDateString()) && Browser.PageSource.Contains(createStudentModel.HispanicLatinoEthnicity.ToString()) && Browser.PageSource.Contains(createStudentModel.Race.Humanize()) && Browser.PageSource.Contains(createStudentModel.HomeLanguage.GetValueOrDefault().ToString()) && Browser.PageSource.Contains(createStudentModel.Address) && Browser.PageSource.Contains(createStudentModel.Address2) && Browser.PageSource.Contains(createStudentModel.City) && Browser.PageSource.Contains(createStudentModel.State.Humanize()) && Browser.PageSource.Contains(createStudentModel.PostalCode); var parentOneFields = Browser.PageSource.Contains(createStudentModel.FirstParent.FirstName) && Browser.PageSource.Contains(createStudentModel.FirstParent.LastName) && Browser.PageSource.Contains(createStudentModel.FirstParent.Sex.Humanize()) && Browser.PageSource.Contains(createStudentModel.FirstParent.RelationshipToStudent.Humanize()) && Browser.PageSource.Contains(createStudentModel.FirstParent.TelephoneNumber) && Browser.PageSource.Contains(createStudentModel.FirstParent.EmailAddress) && Browser.PageSource.Contains(createStudentModel.FirstParent.Address) && Browser.PageSource.Contains(createStudentModel.FirstParent.Address2) && Browser.PageSource.Contains(createStudentModel.FirstParent.City) && Browser.PageSource.Contains(createStudentModel.FirstParent.State.Humanize()) && Browser.PageSource.Contains(createStudentModel.FirstParent.PostalCode); var parentTwoFields = Browser.PageSource.Contains(createStudentModel.SecondParent.FirstName) && Browser.PageSource.Contains(createStudentModel.SecondParent.LastName) && Browser.PageSource.Contains(createStudentModel.SecondParent.Sex.Humanize()) && Browser.PageSource.Contains(createStudentModel.SecondParent.RelationshipToStudent.Humanize()) && Browser.PageSource.Contains(createStudentModel.SecondParent.TelephoneNumber); return(studentFields && parentOneFields && parentTwoFields); }
public IHttpActionResult Create(CreateStudentModel model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); if (string.IsNullOrEmpty(model.MSSV)) { errors.Add("MSSV là trường bắt buộc"); } if (_db.Class.FirstOrDefault(m => m.Id == model.LOP_ID) == null) { errors.Add("ID Lớp trống hoặc không tồn tại"); } if (errors.Errors.Count == 0) { Student sv = new Student(); sv.HoTen = model.HoTen; sv.MSSV = model.MSSV; sv.DiaChi = model.DiaChi; sv.NgaySinh = model.NgaySinh; sv.Class = _db.Class.FirstOrDefault(m => m.Id == model.LOP_ID); sv = _db.Students.Add(sv); this._db.SaveChanges(); StudentModel viewModel = new StudentModel(sv); httpActionResult = Ok(viewModel); } else { httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, errors); } return(httpActionResult); }
public IHttpActionResult TaoSV(CreateStudentModel model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); if (string.IsNullOrEmpty(model.MaSV)) { errors.Add("Mã sv la bat buoc"); } if (string.IsNullOrEmpty(model.HoTenSV)) { errors.Add("Tên sv la bat buoc"); } if (errors.Errors.Count == 0) { Student sv = new Student(); sv.MSSV = model.MaSV; sv.HoTen = model.HoTenSV; sv.DiaChi = model.DiaChi; sv = _db.Students.Add(sv); this._db.SaveChanges(); StudentModel viewModel = new StudentModel(sv); httpActionResult = Ok(viewModel); } else { httpActionResult = Ok(errors); } return(httpActionResult); }
public void HaveEnteredValidInputForAllFields() { _createStudentModel = CreateStudentModelFactory.CreateStudent(); _academicDetailPage = _enrollmentPage.Enroll(_createStudentModel); }
public async Task <CreatedStudentModel> CreateAsync(CreateStudentModel entrant) => new CreatedStudentModel(await _studentService.UpdateAsync(entrant.ToDTO()));
public IActionResult AddStudent(CreateStudentModel model) { model.Create(); return(View(model)); }
public IActionResult AddStudent() { var model = new CreateStudentModel(); return(View(model)); }
public IActionResult AddStudent(CreateStudentModel model) { model.Create(); return(View(model)); //return RedirectToAction("Index"); }