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

            patch.Replace(x => x.Birthday, model.Birthday);
            patch.Replace(x => x.Email, model.Email);
            patch.Replace(x => x.FirstName, model.FirstName);
            patch.Replace(x => x.LastName, model.LastName);
            patch.Replace(x => x.Phone, model.Phone);
            patch.Replace(x => x.UserId, model.UserId);
            return(patch);
        }
Exemple #2
0
        public virtual ApiAdminServerRequestModel MapServerResponseToRequest(
            ApiAdminServerResponseModel response)
        {
            var request = new ApiAdminServerRequestModel();

            request.SetProperties(
                response.Birthday,
                response.Email,
                response.FirstName,
                response.LastName,
                response.Phone,
                response.UserId);
            return(request);
        }
Exemple #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALAdminMapper();
            ApiAdminServerRequestModel model = new ApiAdminServerRequestModel();

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

            response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
            response.UserId.Should().Be(1);
        }
Exemple #4
0
        public virtual ApiAdminServerResponseModel MapServerRequestToResponse(
            int id,
            ApiAdminServerRequestModel request)
        {
            var response = new ApiAdminServerResponseModel();

            response.SetProperties(id,
                                   request.Birthday,
                                   request.Email,
                                   request.FirstName,
                                   request.LastName,
                                   request.Phone,
                                   request.UserId);
            return(response);
        }
Exemple #5
0
        public virtual async Task <CreateResponse <ApiAdminServerResponseModel> > Create(
            ApiAdminServerRequestModel model)
        {
            CreateResponse <ApiAdminServerResponseModel> response = ValidationResponseFactory <ApiAdminServerResponseModel> .CreateResponse(await this.AdminModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Admin record = this.DalAdminMapper.MapModelToEntity(default(int), model);
                record = await this.AdminRepository.Create(record);

                response.SetRecord(this.DalAdminMapper.MapEntityToModel(record));
                await this.mediator.Publish(new AdminCreatedNotification(response.Record));
            }

            return(response);
        }
Exemple #6
0
        public virtual Admin MapModelToEntity(
            int id,
            ApiAdminServerRequestModel model
            )
        {
            Admin item = new Admin();

            item.SetProperties(
                id,
                model.Birthday,
                model.Email,
                model.FirstName,
                model.LastName,
                model.Phone,
                model.UserId);
            return(item);
        }
Exemple #7
0
        public virtual async Task <UpdateResponse <ApiAdminServerResponseModel> > Update(
            int id,
            ApiAdminServerRequestModel model)
        {
            var validationResult = await this.AdminModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Admin record = this.DalAdminMapper.MapModelToEntity(id, model);
                await this.AdminRepository.Update(record);

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

                ApiAdminServerResponseModel apiModel = this.DalAdminMapper.MapEntityToModel(record);
                await this.mediator.Publish(new AdminUpdatedNotification(apiModel));

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