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

            patch.Replace(x => x.Email, model.Email);
            patch.Replace(x => x.Password, model.Password);
            patch.Replace(x => x.StripeCustomerId, model.StripeCustomerId);
            patch.Replace(x => x.SubscriptionTypeId, model.SubscriptionTypeId);
            return(patch);
        }
        public virtual ApiUserServerRequestModel MapServerResponseToRequest(
            ApiUserServerResponseModel response)
        {
            var request = new ApiUserServerRequestModel();

            request.SetProperties(
                response.Email,
                response.Password,
                response.StripeCustomerId,
                response.SubscriptionTypeId);
            return(request);
        }
예제 #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALUserMapper();
            ApiUserServerRequestModel model = new ApiUserServerRequestModel();

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

            response.Email.Should().Be("A");
            response.Password.Should().Be("A");
            response.StripeCustomerId.Should().Be("A");
            response.SubscriptionTypeId.Should().Be(1);
        }
예제 #4
0
        public virtual User MapModelToEntity(
            int id,
            ApiUserServerRequestModel model
            )
        {
            User item = new User();

            item.SetProperties(
                id,
                model.Email,
                model.Password,
                model.StripeCustomerId,
                model.SubscriptionTypeId);
            return(item);
        }
예제 #5
0
        public virtual async Task <CreateResponse <ApiUserServerResponseModel> > Create(
            ApiUserServerRequestModel model)
        {
            CreateResponse <ApiUserServerResponseModel> response = ValidationResponseFactory <ApiUserServerResponseModel> .CreateResponse(await this.UserModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                User record = this.DalUserMapper.MapModelToEntity(default(int), model);
                record = await this.UserRepository.Create(record);

                response.SetRecord(this.DalUserMapper.MapEntityToModel(record));
                await this.mediator.Publish(new UserCreatedNotification(response.Record));
            }

            return(response);
        }
예제 #6
0
        public virtual async Task <UpdateResponse <ApiUserServerResponseModel> > Update(
            int id,
            ApiUserServerRequestModel model)
        {
            var validationResult = await this.UserModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                User record = this.DalUserMapper.MapModelToEntity(id, model);
                await this.UserRepository.Update(record);

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

                ApiUserServerResponseModel apiModel = this.DalUserMapper.MapEntityToModel(record);
                await this.mediator.Publish(new UserUpdatedNotification(apiModel));

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