public JsonPatchDocument <ApiTeacherServerRequestModel> CreatePatch(ApiTeacherServerRequestModel model) { var patch = new JsonPatchDocument <ApiTeacherServerRequestModel>(); patch.Replace(x => x.Birthday, model.Birthday); patch.Replace(x => x.Email, model.Email); patch.Replace(x => x.FirstName, model.FirstName); patch.Replace(x => x.LastName, model.LastName); patch.Replace(x => x.Phone, model.Phone); patch.Replace(x => x.UserId, model.UserId); return(patch); }
public virtual ApiTeacherServerRequestModel MapServerResponseToRequest( ApiTeacherServerResponseModel response) { var request = new ApiTeacherServerRequestModel(); request.SetProperties( response.Birthday, response.Email, response.FirstName, response.LastName, response.Phone, response.UserId); return(request); }
public virtual ApiTeacherServerResponseModel MapServerRequestToResponse( int id, ApiTeacherServerRequestModel request) { var response = new ApiTeacherServerResponseModel(); response.SetProperties(id, request.Birthday, request.Email, request.FirstName, request.LastName, request.Phone, request.UserId); return(response); }
public void MapModelToEntity() { var mapper = new DALTeacherMapper(); ApiTeacherServerRequestModel model = new ApiTeacherServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1); Teacher response = mapper.MapModelToEntity(1, model); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.UserId.Should().Be(1); }
public virtual async Task <CreateResponse <ApiTeacherServerResponseModel> > Create( ApiTeacherServerRequestModel model) { CreateResponse <ApiTeacherServerResponseModel> response = ValidationResponseFactory <ApiTeacherServerResponseModel> .CreateResponse(await this.TeacherModelValidator.ValidateCreateAsync(model)); if (response.Success) { Teacher record = this.DalTeacherMapper.MapModelToEntity(default(int), model); record = await this.TeacherRepository.Create(record); response.SetRecord(this.DalTeacherMapper.MapEntityToModel(record)); await this.mediator.Publish(new TeacherCreatedNotification(response.Record)); } return(response); }
public virtual Teacher MapModelToEntity( int id, ApiTeacherServerRequestModel model ) { Teacher item = new Teacher(); item.SetProperties( id, model.Birthday, model.Email, model.FirstName, model.LastName, model.Phone, model.UserId); return(item); }
public virtual async Task <UpdateResponse <ApiTeacherServerResponseModel> > Update( int id, ApiTeacherServerRequestModel model) { var validationResult = await this.TeacherModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { Teacher record = this.DalTeacherMapper.MapModelToEntity(id, model); await this.TeacherRepository.Update(record); record = await this.TeacherRepository.Get(id); ApiTeacherServerResponseModel apiModel = this.DalTeacherMapper.MapEntityToModel(record); await this.mediator.Publish(new TeacherUpdatedNotification(apiModel)); return(ValidationResponseFactory <ApiTeacherServerResponseModel> .UpdateResponse(apiModel)); } else { return(ValidationResponseFactory <ApiTeacherServerResponseModel> .UpdateResponse(validationResult)); } }