public string UpdateStudent(UpdateStudentRequest request) { var student = _dbContext.Student.FirstOrDefault(student => student.IndexNumber.Equals(request.IndexNumber)); if (student == null) return "Not Found"; student.FirstName = request.FirstName != null ? request.FirstName : student.FirstName; student.LastName = request.LastName != null ? request.LastName : student.LastName; student.BirthDate = request.BirthDate != null ? request.BirthDate : student.BirthDate; _dbContext.Update(student); _dbContext.SaveChanges(); return "OK"; }
public async Task <ActionResult> Update(UpdateStudentRequest request) { var student = new StudentEntity { FirstName = request.FirstName, LastName = request.LastName, DateOfBirth = request.DateOfBirth.Value }; _schoolDbContext.Students.Update(student); await _schoolDbContext.SaveChangesAsync(); return(null); }
public async Task <IActionResult> Update([FromForm] UpdateStudentRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _studentService.Update(request); if (!result.IsSuccessed) { return(BadRequest(result)); } return(Ok(result)); }
public void UpdateStudent(UpdateStudentRequest student) { var stud = _context.Student.SingleOrDefault(s => s.IndexNumber.Equals(student.IndexNumber)); if (stud == null) { throw new NotExistException("Nie ma takiego studenta"); } stud.IndexNumber = student.IndexNumber; stud.FirstName = student.FirstName; stud.LastName = student.LastName; stud.BirthDate = student.BirthDate; stud.IdEnrollment = student.IdEnrollment; _context.SaveChanges(); }
public IResult UpdateStudent(UpdateStudentRequest request) { ICollection <ValidationResult> results = new List <ValidationResult>(); if (!request.Validate(out results)) { return(new Result(false, results.First().ErrorMessage)); } if (!_uow.Students.UpdateStudent(request)) { return(new Result(false, "Could Not Update Student")); } _uow.SaveChanges(); return(new Result(true, "Student Updated Successfully")); }
public ActionResult UpdateStudentEF(UpdateStudentRequest request) { var db = new s16061Context(); var res = new Students { IndexNumber = request.IndexNumber, FirstName = request.FirstName, LastName = request.LastName, Birthdate = request.Birthdate, IdEnrollment = request.IdEnrollment }; db.Entry(res).State = EntityState.Modified; db.SaveChanges(); return(Ok("Zaktualizowano")); }
public void Update(UpdateStudentRequest request, string studentType) { FirstName = request.FirstName; LastName = request.LastName; StudentTypeId = request.StudentTypeId; RaiseEvent(new StudentUpdatedEvent { StudentId = Id, FirstName = FirstName, LastName = LastName, StudentType = studentType, StudentTypeId = StudentTypeId }); }
/// <inheritdoc/> public async Task <StudentResponse> UpdateAsync(int id, UpdateStudentRequest model) { var existingModel = await _repository.GetByIdAsync(id); if (existingModel == null) { return(null); } existingModel.Name = model.Name; existingModel.ModifiedDate = DateTime.Now; existingModel = await _repository.UpdateAsync(existingModel.Id, existingModel); return(PrepareStudentResponse(existingModel)); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] UpdateStudentRequest model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var updatedModel = await _service.UpdateAsync(id, model); if (updatedModel == null) { return(NotFound()); } return(Ok(updatedModel)); }
public bool UpdateStudent(UpdateStudentRequest student) { var result = Collection.Next.Find((x, y) => x.IndexNumber.Span[y] == student.IndexNumber);//.FirstOrDefault(x=>x.IndexNumber == student.IndexNumber); if (!result.success) { return(false); } //student.Map(result.Value); var originalStudent = result.Value; originalStudent.Address1.Span[result.Index] = student.Address1; originalStudent.Address2.Span[result.Index] = student.Address2; originalStudent.Contact1.Span[result.Index] = student.Contact1; originalStudent.Contact2.Span[result.Index] = student.Contact2; originalStudent.Country.Span[result.Index] = student.Country; originalStudent.DateofBirth.Span[result.Index] = student.DateofBirth; //originalStudent.DateOfCompletion.Span[result.Index] = student.DateOfCompletion; originalStudent.DateOfEntry.Span[result.Index] = student.DateOfEntry; //originalStudent.DepartmentId.Span[result.Index] = student.DepartmentId; originalStudent.Disability.Span[result.Index] = student.Disability; //originalStudent.EmergencyContact.Span[result.Index] = student.EmergencyContact; //originalStudent.EnrollmentOption.Span[result.Index] = student.EnrollmentOption; originalStudent.Gender.Span[result.Index] = student.Gender; originalStudent.HomeTown.Span[result.Index] = student.HomeTown; originalStudent.IndexNumber.Span[result.Index] = student.IndexNumber; originalStudent.Level.Span[result.Index] = student.Level; originalStudent.MaritalStatus.Span[result.Index] = student.MaritalStatus; originalStudent.Othernames.Span[result.Index] = student.Othernames; originalStudent.PamentOption.Span[result.Index] = student.PamentOption; originalStudent.PersonalEmail.Span[result.Index] = student.PersonalEmail; originalStudent.ProgramOfStudy.Span[result.Index] = student.ProgramOfStudy; originalStudent.ProgramStatus.Span[result.Index] = student.ProgramStatus; originalStudent.ReferenceNumber.Span[result.Index] = student.ReferenceNumber; originalStudent.Region.Span[result.Index] = student.Region; //originalStudent.RegistrationStatus.Span[result.Index] = student.RegistrationStatus; originalStudent.ResidentialStatus.Span[result.Index] = student.ResidentialStatus; originalStudent.Specialization.Span[result.Index] = student.Specialization; originalStudent.State.Span[result.Index]++; originalStudent.StudentType.Span[result.Index] = student.StudentType; originalStudent.Surname.Span[result.Index] = student.Surname; originalStudent.Title.Span[result.Index] = student.Title; originalStudent.UniversityEmail.Span[result.Index] = student.UniversityEmail; DataWriter.WriterData(result.Value, nameof(Student)); return(true); }
/// <summary> /// Update student's information /// </summary> /// <param name="requestModel"></param> /// <returns></returns> public async Task <UpdateStudentResponse> UpdateStudent(UpdateStudentRequest requestModel) { //Find User with the same id in database var user = await _userService.FindById(requestModel.StudentId); //Check if student already existed in database var student = await _repoWrapper.Student.FindByIdAsync(requestModel.StudentId); //If student already existed, update student student = requestModel.MapToStudent(student); //Update Student student = await _repoWrapper.Student.UpdateAsync(student, student.StudentId); return(UpdateStudentResponse.CreateFromStudent(student)); }
public IActionResult UpdateStudent(string id, UpdateStudentRequest request) { var db = new s16451Context(); var student = db.Student.Single(s => s.IndexNumber == id); if (student == null) { return(NotFound()); } db.Attach(student); if (request.IndexNumber != null) { student.IndexNumber = request.IndexNumber; db.Entry(student).Property("IndexNumber").IsModified = true; } if (request.FirstName != null) { student.FirstName = request.FirstName; db.Entry(student).Property("FirstName").IsModified = true; } if (request.LastName != null) { student.FirstName = request.LastName; db.Entry(student).Property("LastName").IsModified = true; } if (request.BirthDate != null) { student.BirthDate = request.GetBirthDate(); db.Entry(student).Property("BirthDate").IsModified = true; } if (request.Password != null) { student.Password = request.Password; db.Entry(student).Property("Password").IsModified = true; } if (request.IdEnrollment != null) { student.IdEnrollment = request.IdEnrollment.Value; db.Entry(student).Property("IdEnrollemnt").IsModified = true; } db.SaveChanges(); return(Ok("Aktualizacja ukończona")); }
public async Task UpdateStudentAsync(UpdateStudentRequest student) { if (student == null) { throw new InvalidArgumentException("Update student request model cannot be empty."); } var dbStudent = _mapper.Map <DbStudent>(student); try { await _unitOfWork.StudentRepository.UpdateAsync(dbStudent); } catch (DbUpdateConcurrencyException) { throw new NotFoundException(typeof(DbStudent), student.Id); } }
public IActionResult UpdateStudent(string id, UpdateStudentRequest request) { var s = Db_context.Student.Single(s => s.IndexNumber == id); if (s == null) { return(NotFound("Student o nr " + id + " nie został odnaleziony")); } else { s.FirstName = request.FirstName; s.LastName = request.LastName; s.BirthDate = request.BirthDate; s.IdEnrollment = request.IdEnrollment; Db_context.SaveChanges(); return(Ok(s)); } }
public IActionResult UpdateStudent(UpdateStudentRequest updateRequest) { List <Error> errorList = ValidationHelper.ValidateUpdateStudentRequest(updateRequest); if (!errorList.Count.Equals(0)) { return(StatusCode(400, errorList)); } var studentExists = _studentDbService.StudentExists(updateRequest.IndexNumber); if (!studentExists) { return(StatusCode(404, "No student with index " + updateRequest.IndexNumber)); } var response = _studentDbService.UpdateStudent(updateRequest); return(StatusCode(201, response)); }
public void UpdateStudent(string index, UpdateStudentRequest request) { try { var st = new Student(); st.IndexNumber = index; _context.Attach(st); var firstName = request.FirstName; var lastName = request.LastName; var birthDate = request.BirthDate; var idEnrollment = request.IdEnrollment; var entry = _context.Entry(st); if (firstName != null) { st.FirstName = firstName; entry.Property("FirstName").IsModified = true; } if (lastName != null) { st.LastName = lastName; entry.Property("LastName").IsModified = true; } if (birthDate != null) { entry.Property("BirthDate").IsModified = true; } if (idEnrollment > 0) { st.IdEnrollment = idEnrollment; entry.Property("IdEnrollment").IsModified = true; } _context.SaveChanges(); }catch (DbUpdateException exc) { throw new DBException(exc.InnerException.Message); } }
public async Task <int> ModifyStudentAsync(UpdateStudentRequest usr) { var studentExists = _studentContext.Student.Any(s => s.IndexNumber == usr.IndexNumber); if (!studentExists) { return(-1); } var st = new Student { IndexNumber = usr.IndexNumber, FirstName = usr.FirstName, LastName = usr.LastName, BirthDate = DateTime.Parse(usr.BirthDate), IdEnrollment = usr.IdEnrollment }; _studentContext.Attach(st); _studentContext.Entry(st).State = EntityState.Modified; await _studentContext.SaveChangesAsync(); return(0); }
public async Task Should_UpdateExistingStudent() { // arrange IActionResult result; var studentRequest = new UpdateStudentRequest { Name = fixture.UpdatedStudent.Name, Id = ControllerFixture.StudentId }; Student studentResult; // act using (var dbContext = new BlogPostContext(fixture.Options)) { var controller = new StudentsController(dbContext, fixture.Mapper, studentServiceMock.Object, studentRepositoryMock.Object); result = await controller.PutStudent(ControllerFixture.StudentId, studentRequest); studentResult = dbContext.Students.First(x => x.Id == ControllerFixture.StudentId); } //assert var noContentResult = result.As <NoContentResult>(); noContentResult.StatusCode.Should().Be(StatusCodes.Status204NoContent); studentResult.Name.Should().Be(studentRequest.Name); }
public IActionResult UpdateStudent(UpdateStudentRequest student) { _service.UpdateStudent(student); return(Ok()); }
public IActionResult UpdateStudent(string index, UpdateStudentRequest request) { _service.UpdateStudent(index, request); return(Ok()); }
public async Task <string> Put(UpdateStudentRequest request) { await _mediator.ProcessAsync(request); return("Updated"); }
public IActionResult UpdateStudent(string indexNumber, UpdateStudentRequest updateStudentRequest) { _studentsDbService.UpdateStudent(indexNumber, updateStudentRequest); return(Ok("Student with index number " + indexNumber + " was successfully updated")); }
public async Task <IActionResult> UpdateStudent(UpdateStudentRequest student) { await _studentsService.UpdateStudentAsync(student); return(NoContent()); }