Beispiel #1
0
        public virtual ApiBadgeServerResponseModel MapEntityToModel(
            Badge item)
        {
            var model = new ApiBadgeServerResponseModel();

            model.SetProperties(item.Id,
                                item.Date,
                                item.Name,
                                item.UserId);
            if (item.UserIdNavigation != null)
            {
                var userIdModel = new ApiUserServerResponseModel();
                userIdModel.SetProperties(
                    item.UserIdNavigation.Id,
                    item.UserIdNavigation.AboutMe,
                    item.UserIdNavigation.AccountId,
                    item.UserIdNavigation.Age,
                    item.UserIdNavigation.CreationDate,
                    item.UserIdNavigation.DisplayName,
                    item.UserIdNavigation.DownVote,
                    item.UserIdNavigation.EmailHash,
                    item.UserIdNavigation.LastAccessDate,
                    item.UserIdNavigation.Location,
                    item.UserIdNavigation.Reputation,
                    item.UserIdNavigation.UpVote,
                    item.UserIdNavigation.View,
                    item.UserIdNavigation.WebsiteUrl);

                model.SetUserIdNavigation(userIdModel);
            }

            return(model);
        }
        public virtual ApiBadgeClientRequestModel MapServerResponseToClientRequest(
            ApiBadgeServerResponseModel response)
        {
            var request = new ApiBadgeClientRequestModel();

            request.SetProperties(
                response.Date,
                response.Name,
                response.UserId);
            return(request);
        }
        public virtual ApiBadgeServerResponseModel MapServerRequestToResponse(
            int id,
            ApiBadgeServerRequestModel request)
        {
            var response = new ApiBadgeServerResponseModel();

            response.SetProperties(id,
                                   request.Date,
                                   request.Name,
                                   request.UserId);
            return(response);
        }
Beispiel #4
0
        public void MapEntityToModel()
        {
            var   mapper = new DALBadgeMapper();
            Badge item   = new Badge();

            item.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1);
            ApiBadgeServerResponseModel response = mapper.MapEntityToModel(item);

            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
            response.UserId.Should().Be(1);
        }
Beispiel #5
0
        public virtual async Task <UpdateResponse <ApiBadgeServerResponseModel> > Update(
            int id,
            ApiBadgeServerRequestModel model)
        {
            var validationResult = await this.BadgeModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Badge record = this.DalBadgeMapper.MapModelToEntity(id, model);
                await this.BadgeRepository.Update(record);

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

                ApiBadgeServerResponseModel apiModel = this.DalBadgeMapper.MapEntityToModel(record);
                await this.mediator.Publish(new BadgeUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiBadgeServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiBadgeServerResponseModel> .UpdateResponse(validationResult));
            }
        }
Beispiel #6
0
 public BadgeUpdatedNotification(ApiBadgeServerResponseModel record)
 {
     this.Record = record;
 }