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

            patch.Replace(x => x.PublicId, model.PublicId);
            patch.Replace(x => x.TicketStatusId, model.TicketStatusId);
            return(patch);
        }
Exemplo n.º 2
0
        public virtual ApiTicketServerRequestModel MapServerResponseToRequest(
            ApiTicketServerResponseModel response)
        {
            var request = new ApiTicketServerRequestModel();

            request.SetProperties(
                response.PublicId,
                response.TicketStatusId);
            return(request);
        }
Exemplo n.º 3
0
        public void MapModelToEntity()
        {
            var mapper = new DALTicketMapper();
            ApiTicketServerRequestModel model = new ApiTicketServerRequestModel();

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

            response.PublicId.Should().Be("A");
            response.TicketStatusId.Should().Be(1);
        }
Exemplo n.º 4
0
        public virtual ApiTicketServerResponseModel MapServerRequestToResponse(
            int id,
            ApiTicketServerRequestModel request)
        {
            var response = new ApiTicketServerResponseModel();

            response.SetProperties(id,
                                   request.PublicId,
                                   request.TicketStatusId);
            return(response);
        }
Exemplo n.º 5
0
        public virtual Ticket MapModelToEntity(
            int id,
            ApiTicketServerRequestModel model
            )
        {
            Ticket item = new Ticket();

            item.SetProperties(
                id,
                model.PublicId,
                model.TicketStatusId);
            return(item);
        }
Exemplo n.º 6
0
        public virtual async Task <CreateResponse <ApiTicketServerResponseModel> > Create(
            ApiTicketServerRequestModel model)
        {
            CreateResponse <ApiTicketServerResponseModel> response = ValidationResponseFactory <ApiTicketServerResponseModel> .CreateResponse(await this.TicketModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Ticket record = this.DalTicketMapper.MapModelToEntity(default(int), model);
                record = await this.TicketRepository.Create(record);

                response.SetRecord(this.DalTicketMapper.MapEntityToModel(record));
                await this.mediator.Publish(new TicketCreatedNotification(response.Record));
            }

            return(response);
        }
Exemplo n.º 7
0
        public virtual async Task <UpdateResponse <ApiTicketServerResponseModel> > Update(
            int id,
            ApiTicketServerRequestModel model)
        {
            var validationResult = await this.TicketModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Ticket record = this.DalTicketMapper.MapModelToEntity(id, model);
                await this.TicketRepository.Update(record);

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

                ApiTicketServerResponseModel apiModel = this.DalTicketMapper.MapEntityToModel(record);
                await this.mediator.Publish(new TicketUpdatedNotification(apiModel));

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