Exemplo n.º 1
0
        public JsonPatchDocument <ApiHandlerServerRequestModel> CreatePatch(ApiHandlerServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiHandlerServerRequestModel>();

            patch.Replace(x => x.CountryId, model.CountryId);
            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.Phone, model.Phone);
            return(patch);
        }
Exemplo n.º 2
0
        public virtual ApiHandlerServerRequestModel MapServerResponseToRequest(
            ApiHandlerServerResponseModel response)
        {
            var request = new ApiHandlerServerRequestModel();

            request.SetProperties(
                response.CountryId,
                response.Email,
                response.FirstName,
                response.LastName,
                response.Phone);
            return(request);
        }
Exemplo n.º 3
0
        public void MapModelToEntity()
        {
            var mapper = new DALHandlerMapper();
            ApiHandlerServerRequestModel model = new ApiHandlerServerRequestModel();

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

            response.CountryId.Should().Be(1);
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
Exemplo n.º 4
0
        public virtual ApiHandlerServerResponseModel MapServerRequestToResponse(
            int id,
            ApiHandlerServerRequestModel request)
        {
            var response = new ApiHandlerServerResponseModel();

            response.SetProperties(id,
                                   request.CountryId,
                                   request.Email,
                                   request.FirstName,
                                   request.LastName,
                                   request.Phone);
            return(response);
        }
Exemplo n.º 5
0
        public virtual async Task <CreateResponse <ApiHandlerServerResponseModel> > Create(
            ApiHandlerServerRequestModel model)
        {
            CreateResponse <ApiHandlerServerResponseModel> response = ValidationResponseFactory <ApiHandlerServerResponseModel> .CreateResponse(await this.HandlerModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Handler record = this.DalHandlerMapper.MapModelToEntity(default(int), model);
                record = await this.HandlerRepository.Create(record);

                response.SetRecord(this.DalHandlerMapper.MapEntityToModel(record));
                await this.mediator.Publish(new HandlerCreatedNotification(response.Record));
            }

            return(response);
        }
Exemplo n.º 6
0
        public virtual Handler MapModelToEntity(
            int id,
            ApiHandlerServerRequestModel model
            )
        {
            Handler item = new Handler();

            item.SetProperties(
                id,
                model.CountryId,
                model.Email,
                model.FirstName,
                model.LastName,
                model.Phone);
            return(item);
        }
Exemplo n.º 7
0
        public virtual async Task <UpdateResponse <ApiHandlerServerResponseModel> > Update(
            int id,
            ApiHandlerServerRequestModel model)
        {
            var validationResult = await this.HandlerModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Handler record = this.DalHandlerMapper.MapModelToEntity(id, model);
                await this.HandlerRepository.Update(record);

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

                ApiHandlerServerResponseModel apiModel = this.DalHandlerMapper.MapEntityToModel(record);
                await this.mediator.Publish(new HandlerUpdatedNotification(apiModel));

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