Пример #1
0
        public virtual ApiCustomerClientRequestModel MapServerResponseToClientRequest(
            ApiCustomerServerResponseModel response)
        {
            var request = new ApiCustomerClientRequestModel();

            request.SetProperties(
                response.Email,
                response.FirstName,
                response.LastName,
                response.Phone);
            return(request);
        }
Пример #2
0
        public virtual ApiCustomerServerResponseModel MapServerRequestToResponse(
            int id,
            ApiCustomerServerRequestModel request)
        {
            var response = new ApiCustomerServerResponseModel();

            response.SetProperties(id,
                                   request.Email,
                                   request.FirstName,
                                   request.LastName,
                                   request.Phone);
            return(response);
        }
Пример #3
0
        public virtual ApiCustomerServerResponseModel MapEntityToModel(
            Customer item)
        {
            var model = new ApiCustomerServerResponseModel();

            model.SetProperties(item.Id,
                                item.Email,
                                item.FirstName,
                                item.LastName,
                                item.Phone);

            return(model);
        }
Пример #4
0
        public void MapEntityToModel()
        {
            var      mapper = new DALCustomerMapper();
            Customer item   = new Customer();

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

            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.Id.Should().Be(1);
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
Пример #5
0
        public virtual async Task <UpdateResponse <ApiCustomerServerResponseModel> > Update(
            int id,
            ApiCustomerServerRequestModel model)
        {
            var validationResult = await this.CustomerModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Customer record = this.DalCustomerMapper.MapModelToEntity(id, model);
                await this.CustomerRepository.Update(record);

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

                ApiCustomerServerResponseModel apiModel = this.DalCustomerMapper.MapEntityToModel(record);
                await this.mediator.Publish(new CustomerUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiCustomerServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiCustomerServerResponseModel> .UpdateResponse(validationResult));
            }
        }
Пример #6
0
 public CustomerUpdatedNotification(ApiCustomerServerResponseModel record)
 {
     this.Record = record;
 }