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

            patch.Replace(x => x.Name, model.Name);
            patch.Replace(x => x.StripePlanName, model.StripePlanName);
            return(patch);
        }
        public virtual ApiSubscriptionServerRequestModel MapServerResponseToRequest(
            ApiSubscriptionServerResponseModel response)
        {
            var request = new ApiSubscriptionServerRequestModel();

            request.SetProperties(
                response.Name,
                response.StripePlanName);
            return(request);
        }
Exemple #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALSubscriptionMapper();
            ApiSubscriptionServerRequestModel model = new ApiSubscriptionServerRequestModel();

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

            response.Name.Should().Be("A");
            response.StripePlanName.Should().Be("A");
        }
Exemple #4
0
        public virtual Subscription MapModelToEntity(
            int id,
            ApiSubscriptionServerRequestModel model
            )
        {
            Subscription item = new Subscription();

            item.SetProperties(
                id,
                model.Name,
                model.StripePlanName);
            return(item);
        }
Exemple #5
0
        public virtual async Task <CreateResponse <ApiSubscriptionServerResponseModel> > Create(
            ApiSubscriptionServerRequestModel model)
        {
            CreateResponse <ApiSubscriptionServerResponseModel> response = ValidationResponseFactory <ApiSubscriptionServerResponseModel> .CreateResponse(await this.SubscriptionModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Subscription record = this.DalSubscriptionMapper.MapModelToEntity(default(int), model);
                record = await this.SubscriptionRepository.Create(record);

                response.SetRecord(this.DalSubscriptionMapper.MapEntityToModel(record));
                await this.mediator.Publish(new SubscriptionCreatedNotification(response.Record));
            }

            return(response);
        }
Exemple #6
0
        public virtual async Task <UpdateResponse <ApiSubscriptionServerResponseModel> > Update(
            int id,
            ApiSubscriptionServerRequestModel model)
        {
            var validationResult = await this.SubscriptionModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Subscription record = this.DalSubscriptionMapper.MapModelToEntity(id, model);
                await this.SubscriptionRepository.Update(record);

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

                ApiSubscriptionServerResponseModel apiModel = this.DalSubscriptionMapper.MapEntityToModel(record);
                await this.mediator.Publish(new SubscriptionUpdatedNotification(apiModel));

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