public JsonPatchDocument <ApiAddressServerRequestModel> CreatePatch(ApiAddressServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiAddressServerRequestModel>();

            patch.Replace(x => x.Address1, model.Address1);
            patch.Replace(x => x.Address2, model.Address2);
            patch.Replace(x => x.City, model.City);
            patch.Replace(x => x.State, model.State);
            patch.Replace(x => x.Zip, model.Zip);
            return(patch);
        }
        public virtual ApiAddressServerRequestModel MapServerResponseToRequest(
            ApiAddressServerResponseModel response)
        {
            var request = new ApiAddressServerRequestModel();

            request.SetProperties(
                response.Address1,
                response.Address2,
                response.City,
                response.State,
                response.Zip);
            return(request);
        }
        public void MapModelToEntity()
        {
            var mapper = new DALAddressMapper();
            ApiAddressServerRequestModel model = new ApiAddressServerRequestModel();

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

            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.City.Should().Be("A");
            response.State.Should().Be("A");
            response.Zip.Should().Be("A");
        }
        public virtual ApiAddressServerResponseModel MapServerRequestToResponse(
            int id,
            ApiAddressServerRequestModel request)
        {
            var response = new ApiAddressServerResponseModel();

            response.SetProperties(id,
                                   request.Address1,
                                   request.Address2,
                                   request.City,
                                   request.State,
                                   request.Zip);
            return(response);
        }
Example #5
0
        public virtual Address MapModelToEntity(
            int id,
            ApiAddressServerRequestModel model
            )
        {
            Address item = new Address();

            item.SetProperties(
                id,
                model.Address1,
                model.Address2,
                model.City,
                model.State,
                model.Zip);
            return(item);
        }
Example #6
0
        public virtual async Task <CreateResponse <ApiAddressServerResponseModel> > Create(
            ApiAddressServerRequestModel model)
        {
            CreateResponse <ApiAddressServerResponseModel> response = ValidationResponseFactory <ApiAddressServerResponseModel> .CreateResponse(await this.AddressModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Address record = this.DalAddressMapper.MapModelToEntity(default(int), model);
                record = await this.AddressRepository.Create(record);

                response.SetRecord(this.DalAddressMapper.MapEntityToModel(record));
                await this.mediator.Publish(new AddressCreatedNotification(response.Record));
            }

            return(response);
        }
Example #7
0
        public virtual async Task <UpdateResponse <ApiAddressServerResponseModel> > Update(
            int id,
            ApiAddressServerRequestModel model)
        {
            var validationResult = await this.AddressModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Address record = this.DalAddressMapper.MapModelToEntity(id, model);
                await this.AddressRepository.Update(record);

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

                ApiAddressServerResponseModel apiModel = this.DalAddressMapper.MapEntityToModel(record);
                await this.mediator.Publish(new AddressUpdatedNotification(apiModel));

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