Exemple #1
0
        public virtual async Task <CreateResponse <ApiStudentServerResponseModel> > Create(
            ApiStudentServerRequestModel model)
        {
            CreateResponse <ApiStudentServerResponseModel> response = ValidationResponseFactory <ApiStudentServerResponseModel> .CreateResponse(await this.StudentModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Student record = this.DalStudentMapper.MapModelToEntity(default(int), model);
                record = await this.StudentRepository.Create(record);

                response.SetRecord(this.DalStudentMapper.MapEntityToModel(record));
                await this.mediator.Publish(new StudentCreatedNotification(response.Record));
            }

            return(response);
        }
Exemple #2
0
        public JsonPatchDocument <ApiStudentServerRequestModel> CreatePatch(ApiStudentServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiStudentServerRequestModel>();

            patch.Replace(x => x.Birthday, model.Birthday);
            patch.Replace(x => x.Email, model.Email);
            patch.Replace(x => x.EmailRemindersEnabled, model.EmailRemindersEnabled);
            patch.Replace(x => x.FamilyId, model.FamilyId);
            patch.Replace(x => x.FirstName, model.FirstName);
            patch.Replace(x => x.IsAdult, model.IsAdult);
            patch.Replace(x => x.LastName, model.LastName);
            patch.Replace(x => x.Phone, model.Phone);
            patch.Replace(x => x.SmsRemindersEnabled, model.SmsRemindersEnabled);
            patch.Replace(x => x.UserId, model.UserId);
            return(patch);
        }
Exemple #3
0
        public virtual ApiStudentServerRequestModel MapServerResponseToRequest(
            ApiStudentServerResponseModel response)
        {
            var request = new ApiStudentServerRequestModel();

            request.SetProperties(
                response.Birthday,
                response.Email,
                response.EmailRemindersEnabled,
                response.FamilyId,
                response.FirstName,
                response.IsAdult,
                response.LastName,
                response.Phone,
                response.SmsRemindersEnabled,
                response.UserId);
            return(request);
        }
        public void MapModelToEntity()
        {
            var mapper = new DALStudentMapper();
            ApiStudentServerRequestModel model = new ApiStudentServerRequestModel();

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

            response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Email.Should().Be("A");
            response.EmailRemindersEnabled.Should().Be(true);
            response.FamilyId.Should().Be(1);
            response.FirstName.Should().Be("A");
            response.IsAdult.Should().Be(true);
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
            response.SmsRemindersEnabled.Should().Be(true);
            response.UserId.Should().Be(1);
        }
Exemple #5
0
        public virtual Student MapModelToEntity(
            int id,
            ApiStudentServerRequestModel model
            )
        {
            Student item = new Student();

            item.SetProperties(
                id,
                model.Birthday,
                model.Email,
                model.EmailRemindersEnabled,
                model.FamilyId,
                model.FirstName,
                model.IsAdult,
                model.LastName,
                model.Phone,
                model.SmsRemindersEnabled,
                model.UserId);
            return(item);
        }
Exemple #6
0
        public virtual async Task <UpdateResponse <ApiStudentServerResponseModel> > Update(
            int id,
            ApiStudentServerRequestModel model)
        {
            var validationResult = await this.StudentModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Student record = this.DalStudentMapper.MapModelToEntity(id, model);
                await this.StudentRepository.Update(record);

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

                ApiStudentServerResponseModel apiModel = this.DalStudentMapper.MapEntityToModel(record);
                await this.mediator.Publish(new StudentUpdatedNotification(apiModel));

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