public JsonPatchDocument <ApiMessengerServerRequestModel> CreatePatch(ApiMessengerServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiMessengerServerRequestModel>();

            patch.Replace(x => x.Date, model.Date);
            patch.Replace(x => x.FromUserId, model.FromUserId);
            patch.Replace(x => x.MessageId, model.MessageId);
            patch.Replace(x => x.Time, model.Time);
            patch.Replace(x => x.ToUserId, model.ToUserId);
            patch.Replace(x => x.UserId, model.UserId);
            return(patch);
        }
        public virtual ApiMessengerServerRequestModel MapServerResponseToRequest(
            ApiMessengerServerResponseModel response)
        {
            var request = new ApiMessengerServerRequestModel();

            request.SetProperties(
                response.Date,
                response.FromUserId,
                response.MessageId,
                response.Time,
                response.ToUserId,
                response.UserId);
            return(request);
        }
Beispiel #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALMessengerMapper();
            ApiMessengerServerRequestModel model = new ApiMessengerServerRequestModel();

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

            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FromUserId.Should().Be(1);
            response.MessageId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
            response.ToUserId.Should().Be(1);
            response.UserId.Should().Be(1);
        }
        public virtual ApiMessengerServerResponseModel MapServerRequestToResponse(
            int id,
            ApiMessengerServerRequestModel request)
        {
            var response = new ApiMessengerServerResponseModel();

            response.SetProperties(id,
                                   request.Date,
                                   request.FromUserId,
                                   request.MessageId,
                                   request.Time,
                                   request.ToUserId,
                                   request.UserId);
            return(response);
        }
Beispiel #5
0
        public virtual async Task <CreateResponse <ApiMessengerServerResponseModel> > Create(
            ApiMessengerServerRequestModel model)
        {
            CreateResponse <ApiMessengerServerResponseModel> response = ValidationResponseFactory <ApiMessengerServerResponseModel> .CreateResponse(await this.MessengerModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Messenger record = this.DalMessengerMapper.MapModelToEntity(default(int), model);
                record = await this.MessengerRepository.Create(record);

                response.SetRecord(this.DalMessengerMapper.MapEntityToModel(record));
                await this.mediator.Publish(new MessengerCreatedNotification(response.Record));
            }

            return(response);
        }
Beispiel #6
0
        public virtual Messenger MapModelToEntity(
            int id,
            ApiMessengerServerRequestModel model
            )
        {
            Messenger item = new Messenger();

            item.SetProperties(
                id,
                model.Date,
                model.FromUserId,
                model.MessageId,
                model.Time,
                model.ToUserId,
                model.UserId);
            return(item);
        }
Beispiel #7
0
        public virtual async Task <UpdateResponse <ApiMessengerServerResponseModel> > Update(
            int id,
            ApiMessengerServerRequestModel model)
        {
            var validationResult = await this.MessengerModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Messenger record = this.DalMessengerMapper.MapModelToEntity(id, model);
                await this.MessengerRepository.Update(record);

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

                ApiMessengerServerResponseModel apiModel = this.DalMessengerMapper.MapEntityToModel(record);
                await this.mediator.Publish(new MessengerUpdatedNotification(apiModel));

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