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

            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.Notes, model.Notes);
            patch.Replace(x => x.Phone, model.Phone);
            return(patch);
        }
        public virtual ApiCustomerServerRequestModel MapServerResponseToRequest(
            ApiCustomerServerResponseModel response)
        {
            var request = new ApiCustomerServerRequestModel();

            request.SetProperties(
                response.Email,
                response.FirstName,
                response.LastName,
                response.Notes,
                response.Phone);
            return(request);
        }
        public virtual ApiCustomerServerResponseModel MapServerRequestToResponse(
            int id,
            ApiCustomerServerRequestModel request)
        {
            var response = new ApiCustomerServerResponseModel();

            response.SetProperties(id,
                                   request.Email,
                                   request.FirstName,
                                   request.LastName,
                                   request.Notes,
                                   request.Phone);
            return(response);
        }
        public void MapModelToEntity()
        {
            var mapper = new DALCustomerMapper();
            ApiCustomerServerRequestModel model = new ApiCustomerServerRequestModel();

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

            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Notes.Should().Be("A");
            response.Phone.Should().Be("A");
        }
Example #5
0
        public virtual async Task <CreateResponse <ApiCustomerServerResponseModel> > Create(
            ApiCustomerServerRequestModel model)
        {
            CreateResponse <ApiCustomerServerResponseModel> response = ValidationResponseFactory <ApiCustomerServerResponseModel> .CreateResponse(await this.CustomerModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Customer record = this.DalCustomerMapper.MapModelToEntity(default(int), model);
                record = await this.CustomerRepository.Create(record);

                response.SetRecord(this.DalCustomerMapper.MapEntityToModel(record));
                await this.mediator.Publish(new CustomerCreatedNotification(response.Record));
            }

            return(response);
        }
Example #6
0
        public virtual Customer MapModelToEntity(
            int id,
            ApiCustomerServerRequestModel model
            )
        {
            Customer item = new Customer();

            item.SetProperties(
                id,
                model.Email,
                model.FirstName,
                model.LastName,
                model.Notes,
                model.Phone);
            return(item);
        }
Example #7
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));
            }
        }