public IHttpActionResult Put(StudentRequestModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var studentForUpdate = this.data.Students .SearchFor(c => c.FirstName == model.FirstName && c.LastName == model.LastName) .FirstOrDefault(); if (studentForUpdate == null) { return(this.NotFound()); } studentForUpdate.Level = model.Level; studentForUpdate.AdditionalInformation.Address = model.Address; studentForUpdate.AdditionalInformation.Email = model.Email; this.data.Students.Update(studentForUpdate); this.data.SaveChanges(); return(this.Ok(studentForUpdate)); }
public List <Student> Search(StudentRequestModel request) { IQueryable <Student> students = this.repository.Get(); if (!string.IsNullOrWhiteSpace(request.Name)) { students = students.Where(x => x.Name.ToLower().Contains(request.Name.ToLower())); } if (!string.IsNullOrWhiteSpace(request.Phone)) { students = students.Where(x => x.Phone.ToLower().Contains(request.Phone.ToLower())); } students = students.OrderBy(x => x.Modified); if (!string.IsNullOrWhiteSpace(request.OrderBy)) { if (request.OrderBy.ToLower() == "name") { students = request.IsAscending ? students.OrderBy(x => x.Name) : students.OrderByDescending(x => x.Name); } if (request.OrderBy.ToLower() == "phone") { students = request.IsAscending ? students.OrderBy(x => x.Phone) : students.OrderByDescending(x => x.Phone); } } students = students.Skip((request.Page - 1) * 10).Take(request.PerPageCount); List <Student> list = students.ToList(); return(list); }
public IHttpActionResult Put(int id, StudentRequestModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var student = this.data.Students .All() .FirstOrDefault(s => s.Id == id); if (student == null) { return(this.BadRequest("Student with id " + id + " does not exist!")); } student.FirstName = model.FirstName; student.LastName = model.LastName; student.Age = model.Age; student.Number = model.Number; this.data.Students.Update(student); this.data.Students.SaveChanges(); return(this.Ok(model)); }
public async Task <StudentResponseModel> PostStudent( [FromForm] StudentRequestModel model, CancellationToken cancellationToken ) { cancellationToken.ThrowIfCancellationRequested(); var command = new CreateStudentCommand( model.FirstName, model.LastName, model.MiddleName, model.Email, model.Avatar, model.GroupId ); var studentId = await _mediator.Send(command, cancellationToken); var query = new FindStudentByIdQuery(studentId); var student = await _mediator.Send(query, cancellationToken); var response = _mapper.Map <StudentResponseModel>(student); return(response); }
public async Task <IActionResult> PostCreate([FromBody] StudentRequestModel request) { if (request != null) { var student = new Student { UserName = request.UserName, Password = request.Password, ContactNo = request.ContactNo }; context.Add(student); await context.SaveChangesAsync(); var response = new Response { Status = true, Message = "Student record created successfully", Data = new List <StudentRequestModel> { new StudentRequestModel { UserName = request.UserName, Password = request.Password, ContactNo = request.ContactNo } } }; return(Ok(response)); } return(BadRequest()); }
public IHttpActionResult ById(int id) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var dbStudent = this.data .Students .All() .FirstOrDefault(s => s.Id == id); if (dbStudent == null) { return BadRequest("Such student does not exist in database!"); } var student = new StudentRequestModel { Id = dbStudent.Id, Name = dbStudent.Name, Number = dbStudent.Number }; return Ok(student); }
public IHttpActionResult Post(StudentRequestModel request) { StudentService service = new StudentService(); List <Student> students = service.Search(request); return(this.Ok(students)); }
public async Task <ActionResult <Student> > PostStudent(StudentRequestModel student) { string status = ""; switch (student.StatusStudenta) { case 1: status = "Redovan"; break; case 2: status = "Vanredan"; break; } Student new_stud = new Student() { Ime = student.Ime, Prezime = student.Prezime, BrojIndeksa = student.BrojIndeksa, Godina = student.Godina, StatusStudenta = _context.Status_Studenta.Where(x => x.NazivStatusa == status).ToList()[0] }; _context.Studenti.Add(new_stud); await _context.SaveChangesAsync(); return(CreatedAtAction("GetStudent", new { id = student.StudentId }, student)); }
private void Form_Load(object sender, EventArgs e) { studentRequestModel = new StudentRequestModel(""); searchTextBox.DataBindings.Add("Text", studentRequestModel, "Keyword"); List <DropdownViewModel> departments = App.DepartmentService.GetDropdownListAsync(new DepartmentRequestModel()); LoadDropdown(departments); }
public ActionResult AddStudent() { var model = new StudentRequestModel(); model.Teachers = _teacherService.GetAllTeacher(); model.Classrooms = _classroomService.GetAllClassroom(); return(View(model)); }
//get request always takes premitive type public IHttpActionResult Post(StudentRequestModel request) { //searching machanism. StudentService service = new StudentService(); var students = service.Search(request); return(this.Ok(students)); }
public IHttpActionResult Put(int id, StudentRequestModel requestStudent) { var student = Mapper.Map <Student>(requestStudent); student = this.studentsService.Upadte(id, student); return(this.Ok(Mapper.Map <StudentResponseModel>(student))); }
public IHttpActionResult Post(StudentRequestModel requestStudent) { var databaseStudent = Mapper.Map <Student>(requestStudent); databaseStudent = this.studentsService.Add(databaseStudent); return(this.Created("/", databaseStudent.StudentIdentification)); }
public async Task <JsonResult> Update(int id, StudentRequestViewModel viewRequest) { StudentRequestModel request = Mapper.Map <StudentRequestModel>(viewRequest); StudentResponseModel response = await studentSystemApi.Execute(studentsClient.UpdateAsync, id, request); StudentResponseModel viewResponse = Mapper.Map <StudentResponseModel>(response); return(Json(viewResponse)); }
private StudentRequestModel GetStudent() { string userId = User.Identity.GetUserId(); VtaDbContext db = Request.GetOwinContext().Get <VtaDbContext>(); var student = db.Students.Find(userId); StudentRequestModel requestModel = new StudentRequestModel(student); return(requestModel); }
public ActionResult UpdateStudent(int id) { var model = new StudentRequestModel(); model.Student = _studentservice.GetStudentById(id); model.Teachers = _teacherService.GetAllTeacher(); model.Classrooms = _classroomService.GetAllClassroom(); return(View(model)); }
public IHttpActionResult Post(StudentRequestModel requestStudent) { this.studentData.Add(new Student() { FirstName = requestStudent.FirstName, LastName = requestStudent.LastName, Level = requestStudent.Level }); this.studentData.SaveChanges(); return this.Ok(string.Format("student {0} added.", requestStudent.FirstName)); }
public IActionResult UpdateStudent([FromBody] StudentRequestModel requestModel, [FromQuery] int studentId) { try { _studentService.UpdateStudent(requestModel, studentId); return(Ok("Student successfully updated!")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult AddStudent([FromBody] StudentRequestModel student) { try { _studentService.AddStudent(student); return(Ok("Student successfully added!")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Post(StudentRequestModel requestStudent) { this.studentData.Add(new Student() { FirstName = requestStudent.FirstName, LastName = requestStudent.LastName, Level = requestStudent.Level }); this.studentData.SaveChanges(); return(this.Ok(string.Format("student {0} added.", requestStudent.FirstName))); }
public async Task <IActionResult> PutStudent(int id, StudentRequestModel student) { if (id != student.StudentId) { return(BadRequest()); } string status = ""; int id_statusa = 0; switch (student.StatusStudenta) { case 1: status = "Redovan"; id_statusa = 1; break; case 2: status = "Vanredan"; id_statusa = 2; break; } Student updated_stud = await _context.Studenti.FirstAsync(x => x.StudentId == id); updated_stud.Ime = student.Ime; updated_stud.Prezime = student.Prezime; updated_stud.BrojIndeksa = student.BrojIndeksa; updated_stud.Godina = student.Godina; updated_stud.StatusStudenta = new StatusStudenta { StatusStudentaId = id_statusa, NazivStatusa = status }; _context.Entry(updated_stud).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult Post(StudentRequestModel model) { var studentToAdd = new Student { FirstName = model.FirstName, LastName = model.LastName, Level = model.Level, StudentIdentification = model.StudentIdentification, AdditionalInformation = model.AdditionalInformation, Courses = model.Courses }; this.students.Add(studentToAdd); return(this.Ok(string.Format("Student {0} successfully added!", studentToAdd.FirstName))); }
public ActionResult AddStudent(StudentRequestModel model) { var newStudent = new Student(); newStudent.ClassroomId = model.ClassroomId; newStudent.TeacherId = model.TeacherId; newStudent.FullName = model.FullName; newStudent.Email = model.Email; newStudent.PhoneNumber = model.PhoneNumber; newStudent.Address = model.Address; _studentservice.CreateStudent(newStudent); return(RedirectToAction("Index")); }
public ActionResult UpdateStudent(StudentRequestModel model) { var findStudent = _studentservice.GetStudentById(model.StudentId); findStudent.ClassroomId = model.ClassroomId; findStudent.TeacherId = model.TeacherId; findStudent.FullName = model.FullName; findStudent.Email = model.Email; findStudent.PhoneNumber = model.PhoneNumber; findStudent.Address = model.Address; _studentservice.UpdateStudent(findStudent); return(RedirectToAction("Index")); }
public IHttpActionResult Post(StudentRequestModel model) { var studentToAdd = new Student { FirstName = model.FirstName, LastName = model.LastName, Level = model.Level, StudentIdentification = model.StudentIdentification, AdditionalInformation = model.AdditionalInformation, Courses = model.Courses }; this.students.Add(studentToAdd); return this.Ok(string.Format("Student {0} successfully added!", studentToAdd.FirstName)); }
public void AddStudent(StudentRequestModel studentRequestModel) { if (studentRequestModel == null) { throw new Exception("Request model data not valid"); } string email = studentRequestModel.Email; Regex emailRegex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); Match emailMatch = emailRegex.Match(email); if (!emailMatch.Success) { throw new Exception("Mail is not valid"); } string mobile = studentRequestModel.MobilePhone; Regex mobileRegex = new Regex(@"^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$"); Match mobileMatch = mobileRegex.Match(mobile); if (!mobileMatch.Success) { throw new Exception("Mobile number is not valid"); } if (string.IsNullOrEmpty(studentRequestModel.FullName)) { throw new Exception("Full name can not be empty"); } if (studentRequestModel.Subjects.Count < 2) { throw new Exception("At least two subjects need to be added!"); } ; var subjectList = _subjectRepository.GetByIds(studentRequestModel.Subjects).ToList(); var student = new Student() { FullName = studentRequestModel.FullName, Email = studentRequestModel.Email, MobilePhone = studentRequestModel.MobilePhone, Subjects = subjectList }; _studentRepository.Insert(student); }
public StudentResponseModel Update(int id, StudentRequestModel request) { ValidationResult validationResult = validator.Validate(request); if (validationResult.HasErrors) { return(null); } UpdateStudentCommand command = new UpdateStudentCommand(id, request.FirstName, request.LastName, request.Email, request.DateOfBirth); Student student = updateStudentHandler.Handle(command); StudentResponseModel response = studentsMapper.Map(student); return(response); }
public IHttpActionResult Put(int id, StudentRequestModel model) { var studentToUpdate = this.students .All() .FirstOrDefault(c => c.Id == id); if (studentToUpdate == null) { return(this.NotFound()); } if (!this.ModelState.IsValid || model == null) { return(this.BadRequest(this.ModelState)); } studentToUpdate.Name = model.Name; studentToUpdate.FacultyNumber = model.FacultyNumber; foreach (var homeworkId in model.HomeworkIds) { var currentHomework = this.homeworks .All() .FirstOrDefault(h => h.Id == homeworkId); if (currentHomework != null) { studentToUpdate.Homeworks.Add(currentHomework); } } foreach (var courseId in model.CourseIds) { var currentCourse = this.courses .All() .FirstOrDefault(c => c.Id == courseId); if (currentCourse != null) { studentToUpdate.Courses.Add(currentCourse); } } this.students.SaveChanges(); return(this.Ok()); }
public async Task<IActionResult> Post(StudentRequestModel model) { var studentWithSameIdExists = await this.Context.Students .AnyAsync(s => s.Id == model.Id); if (studentWithSameIdExists) { return this.BadRequest(new { error_message = "Student with this Id already exists! " }); } var student = Mapper.Map<Student>(model); await this.Context.Students.AddAsync(student); await this.Context.SaveChangesAsync(); return this.Ok(Mapper.Map<AdminDetailedStudentResponseModel>(student)); }
public IHttpActionResult Post(StudentRequestModel student) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var studentToPost = new Student() { FirstName = student.FirstName, LastName = student.LastName }; this.db.Students.Add(studentToPost); this.db.SaveChanges(); return this.Ok(student); }
public List <StudentGridViewModel> Search(StudentRequestModel request) { //Get Quaryable data IQueryable <Student> students = this.repository.Get(); //condition apply if (!string.IsNullOrWhiteSpace(request.Name)) { students = students.Where(x => x.Name.ToLower().Contains(request.Name.ToLower())); } if (!string.IsNullOrWhiteSpace(request.Phone)) { students = students.Where(x => x.Phone.ToLower().Contains(request.Phone.ToLower())); } students = students.OrderBy(x => x.ModifiedBy); if (!String.IsNullOrWhiteSpace(request.OrderBy)) { if (request.OrderBy.ToLower() == "name") { students = request.IsAcesnding ? students.OrderBy(x => x.Name) : students.OrderByDescending(x => x.Name); } if (request.OrderBy.ToLower() == "phone") { students = request.IsAcesnding ? students.OrderBy(x => x.Phone) : students.OrderByDescending(x => x.Phone); } } students = students.Skip((request.Page - 1) * 10).Take(request.PerpageCount); var list = students.ToList().ConvertAll(x => new StudentGridViewModel(x)); return(list); }
public IHttpActionResult Post(StudentRequestModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var studentToAdd = new Student() { Name = model.Name, FacultyNumber = model.FacultyNumber }; foreach (var homeworkId in model.HomeworkIds) { var currentHomework = this.homeworks .All() .FirstOrDefault(h => h.Id == homeworkId); if (currentHomework != null) { studentToAdd.Homeworks.Add(currentHomework); } } foreach (var courseId in model.CourseIds) { var currentCourse = this.courses .All() .FirstOrDefault(c => c.Id == courseId); if (currentCourse != null) { studentToAdd.Courses.Add(currentCourse); } } this.students.Add(studentToAdd); this.students.SaveChanges(); return(this.Ok()); }
public IHttpActionResult Post(StudentRequestModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var student = new Student { FirstName = model.FirstName, LastName = model.LastName, Age = model.Age, Number = model.Number }; this.data.Students.Add(student); this.data.Students.SaveChanges(); return(this.Ok(student)); }
public IHttpActionResult Create(StudentRequestModel student) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var newStudent = new Student { Name = student.Name, Number = student.Number, }; this.data.Students.Add(newStudent); this.data.SaveChanges(); student.Id = newStudent.Id; return Ok(student); }
public IHttpActionResult Post(StudentRequestModel model) { if (model == null) { return this.BadRequest(); } var db = new StudentSystemDbContext(); var studentsRepo = new GenericRepository<Student>(db); var studentToAdd = new Student { FirstName = model.FirstName, LastName = model.LastName, Level = model.Level }; studentsRepo.Add(studentToAdd); studentsRepo.SaveChanges(); return this.Ok(); }
public void UpdateStudent(StudentRequestModel studentRequestModel, int id) { var student = _studentRepository.GetById(id); if (studentRequestModel == null) { throw new Exception("Request model data not valid"); } string email = studentRequestModel.Email; Regex emailRegex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); Match emailMatch = emailRegex.Match(email); if (!emailMatch.Success) { throw new Exception("Mail is not valid"); } string mobile = studentRequestModel.MobilePhone; Regex mobileRegex = new Regex(@"^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$"); Match mobileMatch = mobileRegex.Match(mobile); if (!mobileMatch.Success) { throw new Exception("Mobile number is not valid"); } if (string.IsNullOrEmpty(studentRequestModel.FullName)) { throw new Exception("Full name can not be empty"); } student.FullName = studentRequestModel.FullName; student.Email = studentRequestModel.Email; student.MobilePhone = studentRequestModel.MobilePhone; _studentRepository.Update(student); }
public IHttpActionResult Post(StudentRequestModel student) { if (student == null) { return this.BadRequest("Student must be set."); } var s = new Student { FirstName = student.FirstName, LastName = student.LastName, Level = student.Level, AdditionalInformation = new StudentInfo { Email = student.Email, Address = student.Address } }; this.data.Students.Add(s); this.data.SaveChanges(); return this.Ok(s.StudentId); }
public IHttpActionResult Put(StudentRequestModel student) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } this.data.Students.Update(new Student { FirstName = student.FirstName, LastName = student.LastName, AdditionalInformation = new StudentInfo { Address = student.Address, Email = student.Email }, Level = student.Level }); this.data.SaveChanges(); return this.Ok(); }
public IHttpActionResult Put(int id, StudentRequestModel model) { var studentToUpdate = this.students .All() .FirstOrDefault(c => c.Id == id); if (studentToUpdate == null) { return this.NotFound(); } if (!this.ModelState.IsValid || model == null) { return this.BadRequest(this.ModelState); } studentToUpdate.Name = model.Name; studentToUpdate.FacultyNumber = model.FacultyNumber; foreach (var homeworkId in model.HomeworkIds) { var currentHomework = this.homeworks .All() .FirstOrDefault(h => h.Id == homeworkId); if (currentHomework != null) { studentToUpdate.Homeworks.Add(currentHomework); } } foreach (var courseId in model.CourseIds) { var currentCourse = this.courses .All() .FirstOrDefault(c => c.Id == courseId); if (currentCourse != null) { studentToUpdate.Courses.Add(currentCourse); } } this.students.SaveChanges(); return this.Ok(); }
public IHttpActionResult Post(StudentRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var studentToAdd = new Student() { Name = model.Name, FacultyNumber = model.FacultyNumber }; foreach (var homeworkId in model.HomeworkIds) { var currentHomework = this.homeworks .All() .FirstOrDefault(h => h.Id == homeworkId); if (currentHomework != null) { studentToAdd.Homeworks.Add(currentHomework); } } foreach (var courseId in model.CourseIds) { var currentCourse = this.courses .All() .FirstOrDefault(c => c.Id == courseId); if (currentCourse != null) { studentToAdd.Courses.Add(currentCourse); } } this.students.Add(studentToAdd); this.students.SaveChanges(); return this.Ok(); }
public IHttpActionResult Update(int id, StudentRequestModel student) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var dbStudent = this.data .Students.All() .FirstOrDefault(s => s.Id == id); if (dbStudent == null) { return BadRequest("Such student does not exist in database!"); } dbStudent.Name = student.Name; dbStudent.Number = student.Number; this.data.SaveChanges(); student.Id = id; return Ok(student); }