Beispiel #1
0
        public JsonPatchDocument <ApiOfficerServerRequestModel> CreatePatch(ApiOfficerServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiOfficerServerRequestModel>();

            patch.Replace(x => x.Badge, model.Badge);
            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.Password, model.Password);
            return(patch);
        }
Beispiel #2
0
        public virtual ApiOfficerServerRequestModel MapServerResponseToRequest(
            ApiOfficerServerResponseModel response)
        {
            var request = new ApiOfficerServerRequestModel();

            request.SetProperties(
                response.Badge,
                response.Email,
                response.FirstName,
                response.LastName,
                response.Password);
            return(request);
        }
Beispiel #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALOfficerMapper();
            ApiOfficerServerRequestModel model = new ApiOfficerServerRequestModel();

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

            response.Badge.Should().Be("A");
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Password.Should().Be("A");
        }
Beispiel #4
0
        public virtual ApiOfficerServerResponseModel MapServerRequestToResponse(
            int id,
            ApiOfficerServerRequestModel request)
        {
            var response = new ApiOfficerServerResponseModel();

            response.SetProperties(id,
                                   request.Badge,
                                   request.Email,
                                   request.FirstName,
                                   request.LastName,
                                   request.Password);
            return(response);
        }
Beispiel #5
0
        public virtual async Task <CreateResponse <ApiOfficerServerResponseModel> > Create(
            ApiOfficerServerRequestModel model)
        {
            CreateResponse <ApiOfficerServerResponseModel> response = ValidationResponseFactory <ApiOfficerServerResponseModel> .CreateResponse(await this.OfficerModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Officer record = this.DalOfficerMapper.MapModelToEntity(default(int), model);
                record = await this.OfficerRepository.Create(record);

                response.SetRecord(this.DalOfficerMapper.MapEntityToModel(record));
                await this.mediator.Publish(new OfficerCreatedNotification(response.Record));
            }

            return(response);
        }
Beispiel #6
0
        public virtual Officer MapModelToEntity(
            int id,
            ApiOfficerServerRequestModel model
            )
        {
            Officer item = new Officer();

            item.SetProperties(
                id,
                model.Badge,
                model.Email,
                model.FirstName,
                model.LastName,
                model.Password);
            return(item);
        }
Beispiel #7
0
        public virtual async Task <UpdateResponse <ApiOfficerServerResponseModel> > Update(
            int id,
            ApiOfficerServerRequestModel model)
        {
            var validationResult = await this.OfficerModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Officer record = this.DalOfficerMapper.MapModelToEntity(id, model);
                await this.OfficerRepository.Update(record);

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

                ApiOfficerServerResponseModel apiModel = this.DalOfficerMapper.MapEntityToModel(record);
                await this.mediator.Publish(new OfficerUpdatedNotification(apiModel));

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