예제 #1
0
        public virtual async Task <CreateResponse <ApiLinkServerResponseModel> > Create(
            ApiLinkServerRequestModel model)
        {
            CreateResponse <ApiLinkServerResponseModel> response = ValidationResponseFactory <ApiLinkServerResponseModel> .CreateResponse(await this.LinkModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Link record = this.DalLinkMapper.MapModelToEntity(default(int), model);
                record = await this.LinkRepository.Create(record);

                response.SetRecord(this.DalLinkMapper.MapEntityToModel(record));
                await this.mediator.Publish(new LinkCreatedNotification(response.Record));
            }

            return(response);
        }
        public JsonPatchDocument <ApiLinkServerRequestModel> CreatePatch(ApiLinkServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiLinkServerRequestModel>();

            patch.Replace(x => x.AssignedMachineId, model.AssignedMachineId);
            patch.Replace(x => x.ChainId, model.ChainId);
            patch.Replace(x => x.DateCompleted, model.DateCompleted);
            patch.Replace(x => x.DateStarted, model.DateStarted);
            patch.Replace(x => x.DynamicParameters, model.DynamicParameters);
            patch.Replace(x => x.ExternalId, model.ExternalId);
            patch.Replace(x => x.LinkStatusId, model.LinkStatusId);
            patch.Replace(x => x.Name, model.Name);
            patch.Replace(x => x.Order, model.Order);
            patch.Replace(x => x.Response, model.Response);
            patch.Replace(x => x.StaticParameters, model.StaticParameters);
            patch.Replace(x => x.TimeoutInSeconds, model.TimeoutInSeconds);
            return(patch);
        }
        public virtual ApiLinkServerRequestModel MapServerResponseToRequest(
            ApiLinkServerResponseModel response)
        {
            var request = new ApiLinkServerRequestModel();

            request.SetProperties(
                response.AssignedMachineId,
                response.ChainId,
                response.DateCompleted,
                response.DateStarted,
                response.DynamicParameters,
                response.ExternalId,
                response.LinkStatusId,
                response.Name,
                response.Order,
                response.Response,
                response.StaticParameters,
                response.TimeoutInSeconds);
            return(request);
        }
예제 #4
0
        public void MapModelToEntity()
        {
            var mapper = new DALLinkMapper();
            ApiLinkServerRequestModel model = new ApiLinkServerRequestModel();

            model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1, "A", 1, "A", "A", 1);
            Link response = mapper.MapModelToEntity(1, model);

            response.AssignedMachineId.Should().Be(1);
            response.ChainId.Should().Be(1);
            response.DateCompleted.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.DateStarted.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.DynamicParameters.Should().Be("A");
            response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.LinkStatusId.Should().Be(1);
            response.Name.Should().Be("A");
            response.Order.Should().Be(1);
            response.Response.Should().Be("A");
            response.StaticParameters.Should().Be("A");
            response.TimeoutInSeconds.Should().Be(1);
        }
예제 #5
0
        public virtual Link MapModelToEntity(
            int id,
            ApiLinkServerRequestModel model
            )
        {
            Link item = new Link();

            item.SetProperties(
                id,
                model.AssignedMachineId,
                model.ChainId,
                model.DateCompleted,
                model.DateStarted,
                model.DynamicParameters,
                model.ExternalId,
                model.LinkStatusId,
                model.Name,
                model.Order,
                model.Response,
                model.StaticParameters,
                model.TimeoutInSeconds);
            return(item);
        }
예제 #6
0
        public virtual async Task <UpdateResponse <ApiLinkServerResponseModel> > Update(
            int id,
            ApiLinkServerRequestModel model)
        {
            var validationResult = await this.LinkModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Link record = this.DalLinkMapper.MapModelToEntity(id, model);
                await this.LinkRepository.Update(record);

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

                ApiLinkServerResponseModel apiModel = this.DalLinkMapper.MapEntityToModel(record);
                await this.mediator.Publish(new LinkUpdatedNotification(apiModel));

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