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

            patch.Replace(x => x.OfficerId, model.OfficerId);
            patch.Replace(x => x.UnitId, model.UnitId);
            return(patch);
        }
        public virtual ApiUnitOfficerServerRequestModel MapServerResponseToRequest(
            ApiUnitOfficerServerResponseModel response)
        {
            var request = new ApiUnitOfficerServerRequestModel();

            request.SetProperties(
                response.OfficerId,
                response.UnitId);
            return(request);
        }
Beispiel #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALUnitOfficerMapper();
            ApiUnitOfficerServerRequestModel model = new ApiUnitOfficerServerRequestModel();

            model.SetProperties(1, 1);
            UnitOfficer response = mapper.MapModelToEntity(1, model);

            response.OfficerId.Should().Be(1);
            response.UnitId.Should().Be(1);
        }
        public virtual ApiUnitOfficerServerResponseModel MapServerRequestToResponse(
            int id,
            ApiUnitOfficerServerRequestModel request)
        {
            var response = new ApiUnitOfficerServerResponseModel();

            response.SetProperties(id,
                                   request.OfficerId,
                                   request.UnitId);
            return(response);
        }
        public virtual UnitOfficer MapModelToEntity(
            int id,
            ApiUnitOfficerServerRequestModel model
            )
        {
            UnitOfficer item = new UnitOfficer();

            item.SetProperties(
                id,
                model.OfficerId,
                model.UnitId);
            return(item);
        }
Beispiel #6
0
        public virtual async Task <CreateResponse <ApiUnitOfficerServerResponseModel> > Create(
            ApiUnitOfficerServerRequestModel model)
        {
            CreateResponse <ApiUnitOfficerServerResponseModel> response = ValidationResponseFactory <ApiUnitOfficerServerResponseModel> .CreateResponse(await this.UnitOfficerModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                UnitOfficer record = this.DalUnitOfficerMapper.MapModelToEntity(default(int), model);
                record = await this.UnitOfficerRepository.Create(record);

                response.SetRecord(this.DalUnitOfficerMapper.MapEntityToModel(record));
                await this.mediator.Publish(new UnitOfficerCreatedNotification(response.Record));
            }

            return(response);
        }
Beispiel #7
0
        public virtual async Task <UpdateResponse <ApiUnitOfficerServerResponseModel> > Update(
            int id,
            ApiUnitOfficerServerRequestModel model)
        {
            var validationResult = await this.UnitOfficerModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                UnitOfficer record = this.DalUnitOfficerMapper.MapModelToEntity(id, model);
                await this.UnitOfficerRepository.Update(record);

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

                ApiUnitOfficerServerResponseModel apiModel = this.DalUnitOfficerMapper.MapEntityToModel(record);
                await this.mediator.Publish(new UnitOfficerUpdatedNotification(apiModel));

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