public static Student StudentDtoModelToEntity(StudentDto studentDto) { var student = new Student(); student.Id = studentDto.Id; student.Pesel = studentDto.Pesel; student.Name = studentDto.Name; student.Surname = studentDto.Surname; student.DateOfBirth = studentDto.DateOfBirth; student.Sex = studentDto.Sex; return(student); }
public async Task <IActionResult> Post([FromBody] StudentDto student) { if (student == null) { return(BadRequest()); } var newStudent = _mapper.Map <Student>(student); _context.Students.Add(newStudent); await _context.SaveChangesAsync(); return(CreatedAtRoute("GetStudent", new { id = newStudent.ID }, newStudent)); }
private void dataGridViewStudent_CellClick(object sender, DataGridViewCellEventArgs e) { if (this.dataGridViewStudent.CurrentRow == null) { return; } var row = this.dataGridViewStudent.CurrentRow; StudentDto student = row.Tag as StudentDto; StudentIspitDto[] studentIspit = this.business.GetStudentIspits(0, student.idStudent); fillDataGridViewStudentIspit(studentIspit); }
/// <summary> /// automapper测试 /// </summary> /// <returns></returns> public async Task <bool> AutoMapperTest() { StudentDto studentDto = new StudentDto() { ID = 1, Name = "fan", CreateTime = DateTime.Now }; Student student = _mapper.Map <Student>(studentDto); return(await Task.FromResult(true)); }
public void TestMethod_TestMethod_WhenAddingStudentCheckLastNameNotExists() { var list = GetStudentList(); StudentDto dto = new StudentDto() { Id = 0, LastName = "Saman" }; if (dto.Id == 0) { CollectionAssert.DoesNotContain(list.Select(x => x.LastName.ToUpper()).ToList(), dto.LastName.ToUpper()); } }
public IActionResult update(int id, StudentDto m) { var student = m.ToStudent(); var updatedStudent = _service.UpdateStudent(id, student); if (updatedStudent == null) { return(BadRequest(new ErrorResponse { Message = $"Problem updating user {id}" })); } return(Ok(updatedStudent.ToDto())); }
public ActionResult Put(StudentDto studentDto) { var result = _StudentValidation.Validate(studentDto); if (result.IsValid) { return(Json(_student.UpdateStudent(studentDto))); } else { return(BadRequest(result.Errors)); } }
public async Task <StudentDto> GetStudentByIdAsync(Guid id, CancellationToken ct) { StudentDto studentDto = null; var studentEntity = await _uow.Students.GetAsync(id, ct); if (studentEntity != null) { studentDto = _mapper.Map <StudentDto>(studentEntity); } return(studentDto); }
public void InsertStudent(StudentDto dtoStudent) { Student student = new Student { ime = dtoStudent.ime, prezime = dtoStudent.prezime, indeksBroj = dtoStudent.indeksBroj, indeksGodina = dtoStudent.indeksGodina }; this._entities.Student.Add(student); this._entities.SaveChanges(); }
public ActionResult Index() { var studentDto = new StudentDto { Email = "addedEmail", FirstName = "addedFirstName", ProfessorId = 1, Projects = new List <ProjectDto>() }; studentService.AddNewStudent(studentDto); return(View()); }
public async Task <ActionResult <Student> > Get(int id) { var props = Props.Create(() => new ConnectionActor(AkkaService.CClientSettings)); var actor = AkkaService.ActorSys.ActorOf(props); var result = await actor.Ask <GetResult>(new Get(id)); var student = StudentDto.FromWierdAkkaJson(result.Json); return(Ok(student)); // return _students.Find(x => x.Id == id); }
public async Task <bool> DeleteStudentAsync(StudentDto studentDto) { OnDelete(studentDto); var entity = _context.Students .Where(x => x.Id == studentDto.Id) .FirstOrDefault(); if (entity != null) { _context.Students.Remove(entity); OnBeforeDelete(entity); try { await _context.SaveChangesAsync(); } catch (DbUpdateException ex) { // _context.Entry(entity).State = EntityState.Detached; var sqlException = ex.GetBaseException() as SqlException; if (sqlException != null) { var errorMessage = "deleting error"; var number = sqlException.Number; if (number == 547) { string table = GetErrorTable(sqlException) ?? "descendant"; errorMessage = $"Must delete {table} records before deleting Student"; } throw new Exception(errorMessage, ex); } } finally { // _context.Entry(entity).State = EntityState.Detached; } OnAfterDelete(entity); } else { return(false); } return(true); }
public HttpResponseMessage Post(StudentDto value) { var newStudent = new Student { SchoolId = value.SchoolId, FirstName = value.FirstName, LastName = value.LastName, Age = value.Age, Grade = value.Grade }; HttpResponseMessage response; try { apiControllerHelper.Post <Student>(newStudent); if (value.Marks != null) { foreach (var mark in value.Marks) { apiControllerHelper.Post <Mark>(new Mark { StudentId = newStudent.Id, Subject = mark.Subject, Value = mark.Value }); } } var createdStudentDto = new StudentDto() { Id = newStudent.Id, FirstName = newStudent.FirstName, LastName = newStudent.LastName, Age = newStudent.Age, Grade = newStudent.Grade }; response = Request.CreateResponse <StudentDto>(HttpStatusCode.Created, createdStudentDto); var resourceLink = Url.Link("DefaultApi", new { id = createdStudentDto.Id }); response.Headers.Location = new Uri(resourceLink); } catch (Exception ex) { response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex); } return(response); }
private Student MapObj(StudentDto newStudent) { Student student = new Student { Id = newStudent.Id, UserName = newStudent.UserName, FirstName = newStudent.FirstName, LastName = newStudent.LastName, Age = newStudent.Age, Career = newStudent.Career }; return(student); }
private StudentDto MapToConcreteObj(Student student) { StudentDto studentDto = new StudentDto { Id = student.Id, UserName = student.UserName, FirstName = student.FirstName, LastName = student.LastName, Age = student.Age, Career = student.Career }; return(studentDto); }
public IActionResult Editar(int id) { var student = _studentRepository.GetById(id); var dto = new StudentDto { Id = student.Id, Name = student.Name, Nif = student.Nif, Email = student.Email, TargetAudience = student.TargetAudience.ToString() }; return(View("NovoOuEditar", dto)); }
public static SignupStudentCourseCommand Get(long courseId, string studentName, int studentAge) { var student = new StudentDto() { Name = studentName, Age = studentAge }; return(new SignupStudentCourseCommand { CourseId = courseId, Student = student }); }
public ParentDto ParentToParentDto(Parent parent) { ParentDto user = db.ParentsRepository.ParentToParentDto(parent); if (user != null && parent.Students != null) { foreach (var student in parent.Students) { StudentDto studentDto = db.StudentsRepository.StudentToStudentDto(student); user.Students.Add(studentDto); } } return(user); }
public async Task <IActionResult> Create([FromBody] StudentDto student) { if (ModelState.IsValid) { _context.Add(new Student() { Age = student.Age, LastName = student.LastName, FirstMidName = student.FirstMidName }); await _context.SaveChangesAsync(); return(Ok()); } return(BadRequest()); }
public static List <StudentDto> Convert(Students students) { if (students != null) { List <StudentDto> studentsDto = new List <StudentDto>(); foreach (Student student in students) { StudentDto item = ConvertToDto(student); studentsDto.Add(item); } return(studentsDto); } return(null); }
public IHttpActionResult Create(StudentDto studentDto) { if (!ModelState.IsValid) { return(BadRequest()); } var student = Mapper.Map <StudentDto, Student>(studentDto); db.Students.Add(student); db.SaveChanges(); studentDto.StudentID = student.StudentID; return(Created(new Uri(Request.RequestUri + "/" + student.StudentID), studentDto)); }
} //Sprawdz czy pesel istnieje public bool ChangePersonalDataStudent(StudentDto studentDto) { var student = Mappers.DtoToEntityMapper.StudentDtoModelToEntity(studentDto); if (_studentRepoService.ChangeStudentPersonalData(student)) { return(true);//zmieniono dane klienta } else { return(false);//zmieniono dane klienta } } //zmien dane personalne studenta
public async Task <ActionResult> AddStudentAsync(int courseId, StudentDto student) { var message = new SignupMessageContent { CourseId = courseId, StudentAge = student.Age, StudentName = student.Name, StudentEmail = student.Email }; await _queueClient.SendMessage(message); return(Accepted()); }
public ActionResult <StudentDto> AddStudent(StudentDto s) { try { int newId = _serviceStudent.AddStudent(_mapper.Map <StudentDto, Student>(s)); Student newStudent = _serviceStudent.GetStudent(newId); var result = _mapper.Map <Student, StudentDto>(newStudent); return(Ok(result)); } catch (Exception ex) { _logger.LogError(ex.Message); return(BadRequest(ex.Message)); } }
public async Task <ActionResult <StudentDto> > AddAsync(StudentDto dto) { var validator = new DefaultStudentValidator(_studentValidationService); var entry = await Student.BuildAsync(validator, dto.SexId, dto.Firstname, dto.Middlename, dto.Lastname, dto.Callsign); if (entry.HasErrors) { return(BadRequest(entry.ErrorsStrings)); } entry = await _studentCrudService.AddAsync(entry); return(Ok(entry)); }
public void Update(StudentDto studentDto) { var student = _db.StudentRepository.Get(studentDto.Id); if (student == null) { throw new ArgumentException($"There is no student with id {studentDto.Id}"); } student.Name = studentDto.Name; student.City = studentDto.City; _db.StudentRepository.Update(student); _db.Save(); }
public Student CreateStudent(StudentDto studentDto) { Student s = new Student { Name = studentDto.Name, Address = studentDto.Address + " GR", Dob = studentDto.Dob, }; using CollegeDbContent college = new CollegeDbContent(); college.Students.Add(s); college.SaveChanges(); return(s); }
public IActionResult UpdateStudent(string indexNumber, StudentDto studentDto) { var db = new s17179Context(); var student = db.Student .Where(s => s.IndexNumber == indexNumber) .Single(); student.FirstName = studentDto.FirstName; student.LastName = studentDto.LastName; db.SaveChanges(); return(Ok(student)); }
public void Update(int id, StudentDto obj) { var find = dbContext.Students.Find(id); if (find == null) { throw new EntityNotFoundException("Student "); } find.Ime = obj.Ime; find.Prezime = obj.Prezime; find.Adresa = obj.Adresa; find.Datum_rodjenja = obj.Datum_rodjenja; find.Broj_index = obj.Broj_indeks; }
public async Task <ActionResult <StudentDto> > TestPost(StudentDto studentDto) { int x = 0; return(await Task.Run(() => { return new StudentDto { Id = 1, Age = 18, Name = "AAA" }; })); }
public static StudentDto MergeWithPrototype(this StudentPrototype student, StudentDto dto) { dto.AmountFromEnvelope = student.AmountFromEnvelope.CastToDecimal(); dto.AmountFromWebsite = student.AmountFromWebsite.CastToDecimal(); dto.FundraisingGoal = student.FundraisingGoal.CastToDecimal(); dto.EnvelopeNumber = student.EnvelopeNumber; dto.FirstName = student.FirstName; dto.LastName = student.LastName; dto.Grade = student.Grade; dto.MinutesRead = student.MinutesRead.CastToInt(); dto.PagesRead = student.PagesRead.CastToInt(); dto.ReadingGoal = student.ReadingGoal.CastToInt(); dto.School = student.School; dto.ShirtSize = student.ShirtSize; dto.Address1 = student.Address1; dto.Address2 = student.Address2; dto.City = student.City; dto.State = student.State; dto.Zip = student.Zip; dto.Phone = student.Phone; dto.Teacher = student.Teacher; return dto; }
public void Delete(StudentDto studentDto) { _session.Delete(studentDto); }
public void Save(StudentDto student) { _session.Flush(); _session.Save(student); _session.Flush(); }