Exemple #1
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);
        }
Exemple #2
0
        public JsonPatchDocument <ApiUserServerRequestModel> CreatePatch(ApiUserServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiUserServerRequestModel>();

            patch.Replace(x => x.AboutMe, model.AboutMe);
            patch.Replace(x => x.AccountId, model.AccountId);
            patch.Replace(x => x.Age, model.Age);
            patch.Replace(x => x.CreationDate, model.CreationDate);
            patch.Replace(x => x.DisplayName, model.DisplayName);
            patch.Replace(x => x.DownVote, model.DownVote);
            patch.Replace(x => x.EmailHash, model.EmailHash);
            patch.Replace(x => x.LastAccessDate, model.LastAccessDate);
            patch.Replace(x => x.Location, model.Location);
            patch.Replace(x => x.Reputation, model.Reputation);
            patch.Replace(x => x.UpVote, model.UpVote);
            patch.Replace(x => x.View, model.View);
            patch.Replace(x => x.WebsiteUrl, model.WebsiteUrl);
            return(patch);
        }
Exemple #3
0
        public virtual ApiUserServerRequestModel MapServerResponseToRequest(
            ApiUserServerResponseModel response)
        {
            var request = new ApiUserServerRequestModel();

            request.SetProperties(
                response.AboutMe,
                response.AccountId,
                response.Age,
                response.CreationDate,
                response.DisplayName,
                response.DownVote,
                response.EmailHash,
                response.LastAccessDate,
                response.Location,
                response.Reputation,
                response.UpVote,
                response.View,
                response.WebsiteUrl);
            return(request);
        }
Exemple #4
0
        public void MapModelToEntity()
        {
            var mapper = new DALUserMapper();
            ApiUserServerRequestModel model = new ApiUserServerRequestModel();

            model.SetProperties("A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, 1, "A");
            User response = mapper.MapModelToEntity(1, model);

            response.AboutMe.Should().Be("A");
            response.AccountId.Should().Be(1);
            response.Age.Should().Be(1);
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.DisplayName.Should().Be("A");
            response.DownVote.Should().Be(1);
            response.EmailHash.Should().Be("A");
            response.LastAccessDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Location.Should().Be("A");
            response.Reputation.Should().Be(1);
            response.UpVote.Should().Be(1);
            response.View.Should().Be(1);
            response.WebsiteUrl.Should().Be("A");
        }
Exemple #5
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));
            }
        }
Exemple #6
0
        public virtual User MapModelToEntity(
            int id,
            ApiUserServerRequestModel model
            )
        {
            User item = new User();

            item.SetProperties(
                id,
                model.AboutMe,
                model.AccountId,
                model.Age,
                model.CreationDate,
                model.DisplayName,
                model.DownVote,
                model.EmailHash,
                model.LastAccessDate,
                model.Location,
                model.Reputation,
                model.UpVote,
                model.View,
                model.WebsiteUrl);
            return(item);
        }