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

            patch.Replace(x => x.FirstName, model.FirstName);
            patch.Replace(x => x.IsSalesPerson, model.IsSalesPerson);
            patch.Replace(x => x.IsShipper, model.IsShipper);
            patch.Replace(x => x.LastName, model.LastName);
            return(patch);
        }
Ejemplo n.º 2
0
        public virtual ApiEmployeeServerRequestModel MapServerResponseToRequest(
            ApiEmployeeServerResponseModel response)
        {
            var request = new ApiEmployeeServerRequestModel();

            request.SetProperties(
                response.FirstName,
                response.IsSalesPerson,
                response.IsShipper,
                response.LastName);
            return(request);
        }
Ejemplo n.º 3
0
        public virtual ApiEmployeeServerResponseModel MapServerRequestToResponse(
            int id,
            ApiEmployeeServerRequestModel request)
        {
            var response = new ApiEmployeeServerResponseModel();

            response.SetProperties(id,
                                   request.FirstName,
                                   request.IsSalesPerson,
                                   request.IsShipper,
                                   request.LastName);
            return(response);
        }
Ejemplo n.º 4
0
        public void MapModelToEntity()
        {
            var mapper = new DALEmployeeMapper();
            ApiEmployeeServerRequestModel model = new ApiEmployeeServerRequestModel();

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

            response.FirstName.Should().Be("A");
            response.IsSalesPerson.Should().Be(true);
            response.IsShipper.Should().Be(true);
            response.LastName.Should().Be("A");
        }
Ejemplo n.º 5
0
        public virtual Employee MapModelToEntity(
            int id,
            ApiEmployeeServerRequestModel model
            )
        {
            Employee item = new Employee();

            item.SetProperties(
                id,
                model.FirstName,
                model.IsSalesPerson,
                model.IsShipper,
                model.LastName);
            return(item);
        }
Ejemplo n.º 6
0
        public virtual async Task <CreateResponse <ApiEmployeeServerResponseModel> > Create(
            ApiEmployeeServerRequestModel model)
        {
            CreateResponse <ApiEmployeeServerResponseModel> response = ValidationResponseFactory <ApiEmployeeServerResponseModel> .CreateResponse(await this.EmployeeModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Employee record = this.DalEmployeeMapper.MapModelToEntity(default(int), model);
                record = await this.EmployeeRepository.Create(record);

                response.SetRecord(this.DalEmployeeMapper.MapEntityToModel(record));
                await this.mediator.Publish(new EmployeeCreatedNotification(response.Record));
            }

            return(response);
        }
Ejemplo n.º 7
0
        public virtual async Task <UpdateResponse <ApiEmployeeServerResponseModel> > Update(
            int id,
            ApiEmployeeServerRequestModel model)
        {
            var validationResult = await this.EmployeeModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Employee record = this.DalEmployeeMapper.MapModelToEntity(id, model);
                await this.EmployeeRepository.Update(record);

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

                ApiEmployeeServerResponseModel apiModel = this.DalEmployeeMapper.MapEntityToModel(record);
                await this.mediator.Publish(new EmployeeUpdatedNotification(apiModel));

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