Пример #1
0
        public JsonPatchDocument <ApiAirlineServerRequestModel> CreatePatch(ApiAirlineServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiAirlineServerRequestModel>();

            patch.Replace(x => x.Name, model.Name);
            return(patch);
        }
Пример #2
0
        public virtual ApiAirlineServerRequestModel MapServerResponseToRequest(
            ApiAirlineServerResponseModel response)
        {
            var request = new ApiAirlineServerRequestModel();

            request.SetProperties(
                response.Name);
            return(request);
        }
Пример #3
0
        public virtual ApiAirlineServerResponseModel MapServerRequestToResponse(
            int id,
            ApiAirlineServerRequestModel request)
        {
            var response = new ApiAirlineServerResponseModel();

            response.SetProperties(id,
                                   request.Name);
            return(response);
        }
Пример #4
0
        public void MapModelToEntity()
        {
            var mapper = new DALAirlineMapper();
            ApiAirlineServerRequestModel model = new ApiAirlineServerRequestModel();

            model.SetProperties("A");
            Airline response = mapper.MapModelToEntity(1, model);

            response.Name.Should().Be("A");
        }
Пример #5
0
        public virtual Airline MapModelToEntity(
            int id,
            ApiAirlineServerRequestModel model
            )
        {
            Airline item = new Airline();

            item.SetProperties(
                id,
                model.Name);
            return(item);
        }
Пример #6
0
        public virtual async Task <CreateResponse <ApiAirlineServerResponseModel> > Create(
            ApiAirlineServerRequestModel model)
        {
            CreateResponse <ApiAirlineServerResponseModel> response = ValidationResponseFactory <ApiAirlineServerResponseModel> .CreateResponse(await this.AirlineModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Airline record = this.DalAirlineMapper.MapModelToEntity(default(int), model);
                record = await this.AirlineRepository.Create(record);

                response.SetRecord(this.DalAirlineMapper.MapEntityToModel(record));
                await this.mediator.Publish(new AirlineCreatedNotification(response.Record));
            }

            return(response);
        }
Пример #7
0
        public virtual async Task <UpdateResponse <ApiAirlineServerResponseModel> > Update(
            int id,
            ApiAirlineServerRequestModel model)
        {
            var validationResult = await this.AirlineModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Airline record = this.DalAirlineMapper.MapModelToEntity(id, model);
                await this.AirlineRepository.Update(record);

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

                ApiAirlineServerResponseModel apiModel = this.DalAirlineMapper.MapEntityToModel(record);
                await this.mediator.Publish(new AirlineUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiAirlineServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiAirlineServerResponseModel> .UpdateResponse(validationResult));
            }
        }