Exemple #1
0
        public JsonPatchDocument <ApiEventServerRequestModel> CreatePatch(ApiEventServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiEventServerRequestModel>();

            patch.Replace(x => x.Address1, model.Address1);
            patch.Replace(x => x.Address2, model.Address2);
            patch.Replace(x => x.CityId, model.CityId);
            patch.Replace(x => x.Date, model.Date);
            patch.Replace(x => x.Description, model.Description);
            patch.Replace(x => x.EndDate, model.EndDate);
            patch.Replace(x => x.Facebook, model.Facebook);
            patch.Replace(x => x.Name, model.Name);
            patch.Replace(x => x.StartDate, model.StartDate);
            patch.Replace(x => x.Website, model.Website);
            return(patch);
        }
Exemple #2
0
        public virtual async Task <CreateResponse <ApiEventServerResponseModel> > Create(
            ApiEventServerRequestModel model)
        {
            CreateResponse <ApiEventServerResponseModel> response = ValidationResponseFactory <ApiEventServerResponseModel> .CreateResponse(await this.EventModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Event record = this.DalEventMapper.MapModelToEntity(default(int), model);
                record = await this.EventRepository.Create(record);

                response.SetRecord(this.DalEventMapper.MapEntityToModel(record));
                await this.mediator.Publish(new EventCreatedNotification(response.Record));
            }

            return(response);
        }
Exemple #3
0
        public virtual ApiEventServerRequestModel MapServerResponseToRequest(
            ApiEventServerResponseModel response)
        {
            var request = new ApiEventServerRequestModel();

            request.SetProperties(
                response.Address1,
                response.Address2,
                response.CityId,
                response.Date,
                response.Description,
                response.EndDate,
                response.Facebook,
                response.Name,
                response.StartDate,
                response.Website);
            return(request);
        }
        public void MapModelToEntity()
        {
            var mapper = new DALEventMapper();
            ApiEventServerRequestModel model = new ApiEventServerRequestModel();

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

            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.CityId.Should().Be(1);
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Description.Should().Be("A");
            response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Facebook.Should().Be("A");
            response.Name.Should().Be("A");
            response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Website.Should().Be("A");
        }
Exemple #5
0
        public virtual Event MapModelToEntity(
            int id,
            ApiEventServerRequestModel model
            )
        {
            Event item = new Event();

            item.SetProperties(
                id,
                model.Address1,
                model.Address2,
                model.CityId,
                model.Date,
                model.Description,
                model.EndDate,
                model.Facebook,
                model.Name,
                model.StartDate,
                model.Website);
            return(item);
        }
Exemple #6
0
        public virtual async Task <UpdateResponse <ApiEventServerResponseModel> > Update(
            int id,
            ApiEventServerRequestModel model)
        {
            var validationResult = await this.EventModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Event record = this.DalEventMapper.MapModelToEntity(id, model);
                await this.EventRepository.Update(record);

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

                ApiEventServerResponseModel apiModel = this.DalEventMapper.MapEntityToModel(record);
                await this.mediator.Publish(new EventUpdatedNotification(apiModel));

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