Пример #1
0
        public virtual async Task <CreateResponse <ApiFileServerResponseModel> > Create(
            ApiFileServerRequestModel model)
        {
            CreateResponse <ApiFileServerResponseModel> response = ValidationResponseFactory <ApiFileServerResponseModel> .CreateResponse(await this.FileModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                File record = this.DalFileMapper.MapModelToEntity(default(int), model);
                record = await this.FileRepository.Create(record);

                response.SetRecord(this.DalFileMapper.MapEntityToModel(record));
                await this.mediator.Publish(new FileCreatedNotification(response.Record));
            }

            return(response);
        }
        public JsonPatchDocument <ApiFileServerRequestModel> CreatePatch(ApiFileServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiFileServerRequestModel>();

            patch.Replace(x => x.BucketId, model.BucketId);
            patch.Replace(x => x.DateCreated, model.DateCreated);
            patch.Replace(x => x.Description, model.Description);
            patch.Replace(x => x.Expiration, model.Expiration);
            patch.Replace(x => x.Extension, model.Extension);
            patch.Replace(x => x.ExternalId, model.ExternalId);
            patch.Replace(x => x.FileSizeInByte, model.FileSizeInByte);
            patch.Replace(x => x.FileTypeId, model.FileTypeId);
            patch.Replace(x => x.Location, model.Location);
            patch.Replace(x => x.PrivateKey, model.PrivateKey);
            patch.Replace(x => x.PublicKey, model.PublicKey);
            return(patch);
        }
        public virtual ApiFileServerRequestModel MapServerResponseToRequest(
            ApiFileServerResponseModel response)
        {
            var request = new ApiFileServerRequestModel();

            request.SetProperties(
                response.BucketId,
                response.DateCreated,
                response.Description,
                response.Expiration,
                response.Extension,
                response.ExternalId,
                response.FileSizeInByte,
                response.FileTypeId,
                response.Location,
                response.PrivateKey,
                response.PublicKey);
            return(request);
        }
Пример #4
0
        public void MapModelToEntity()
        {
            var mapper = new DALFileMapper();
            ApiFileServerRequestModel model = new ApiFileServerRequestModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1m, 1, "A", "A", "A");
            File response = mapper.MapModelToEntity(1, model);

            response.BucketId.Should().Be(1);
            response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Description.Should().Be("A");
            response.Expiration.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Extension.Should().Be("A");
            response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.FileSizeInByte.Should().Be(1m);
            response.FileTypeId.Should().Be(1);
            response.Location.Should().Be("A");
            response.PrivateKey.Should().Be("A");
            response.PublicKey.Should().Be("A");
        }
Пример #5
0
        public virtual File MapModelToEntity(
            int id,
            ApiFileServerRequestModel model
            )
        {
            File item = new File();

            item.SetProperties(
                id,
                model.BucketId,
                model.DateCreated,
                model.Description,
                model.Expiration,
                model.Extension,
                model.ExternalId,
                model.FileSizeInByte,
                model.FileTypeId,
                model.Location,
                model.PrivateKey,
                model.PublicKey);
            return(item);
        }
Пример #6
0
        public virtual async Task <UpdateResponse <ApiFileServerResponseModel> > Update(
            int id,
            ApiFileServerRequestModel model)
        {
            var validationResult = await this.FileModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                File record = this.DalFileMapper.MapModelToEntity(id, model);
                await this.FileRepository.Update(record);

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

                ApiFileServerResponseModel apiModel = this.DalFileMapper.MapEntityToModel(record);
                await this.mediator.Publish(new FileUpdatedNotification(apiModel));

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