示例#1
0
        public virtual ApiPetServerResponseModel MapEntityToModel(
            Pet item)
        {
            var model = new ApiPetServerResponseModel();

            model.SetProperties(item.Id,
                                item.AcquiredDate,
                                item.BreedId,
                                item.Description,
                                item.PenId,
                                item.Price);
            if (item.BreedIdNavigation != null)
            {
                var breedIdModel = new ApiBreedServerResponseModel();
                breedIdModel.SetProperties(
                    item.BreedIdNavigation.Id,
                    item.BreedIdNavigation.Name,
                    item.BreedIdNavigation.SpeciesId);

                model.SetBreedIdNavigation(breedIdModel);
            }

            if (item.PenIdNavigation != null)
            {
                var penIdModel = new ApiPenServerResponseModel();
                penIdModel.SetProperties(
                    item.PenIdNavigation.Id,
                    item.PenIdNavigation.Name);

                model.SetPenIdNavigation(penIdModel);
            }

            return(model);
        }
示例#2
0
        public virtual ApiPenClientRequestModel MapServerResponseToClientRequest(
            ApiPenServerResponseModel response)
        {
            var request = new ApiPenClientRequestModel();

            request.SetProperties(
                response.Name);
            return(request);
        }
示例#3
0
        public virtual ApiPenServerResponseModel MapEntityToModel(
            Pen item)
        {
            var model = new ApiPenServerResponseModel();

            model.SetProperties(item.Id,
                                item.Name);

            return(model);
        }
示例#4
0
        public virtual ApiPenServerResponseModel MapServerRequestToResponse(
            int id,
            ApiPenServerRequestModel request)
        {
            var response = new ApiPenServerResponseModel();

            response.SetProperties(id,
                                   request.Name);
            return(response);
        }
示例#5
0
        public void MapEntityToModel()
        {
            var mapper = new DALPenMapper();
            Pen item   = new Pen();

            item.SetProperties(1, "A");
            ApiPenServerResponseModel response = mapper.MapEntityToModel(item);

            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
        }
示例#6
0
        public virtual async Task <UpdateResponse <ApiPenServerResponseModel> > Update(
            int id,
            ApiPenServerRequestModel model)
        {
            var validationResult = await this.PenModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Pen record = this.DalPenMapper.MapModelToEntity(id, model);
                await this.PenRepository.Update(record);

                record = await this.PenRepository.Get(id);

                ApiPenServerResponseModel apiModel = this.DalPenMapper.MapEntityToModel(record);
                await this.mediator.Publish(new PenUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiPenServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiPenServerResponseModel> .UpdateResponse(validationResult));
            }
        }
示例#7
0
 public PenUpdatedNotification(ApiPenServerResponseModel record)
 {
     this.Record = record;
 }
 public void SetPenIdNavigation(ApiPenServerResponseModel value)
 {
     this.PenIdNavigation = value;
 }