public async Task <int> AddImageProperty(ImagePropertyModelView imageProperty, CancellationToken token = default)
        {
            var property = await _uow.GetObjectByKeyAsync <Property>(imageProperty.IdProperty);

            if (property == null)
            {
                property = await CreateDefaultPropertyBuildingAsync();
            }
            var propertyImage = new PropertyImage(_uow);

            propertyImage.Enabled  = true;
            propertyImage.FileName = imageProperty.File.FileName;
            propertyImage.Property = property;
            using (MemoryStream fileStream = new MemoryStream())
            {
                await imageProperty.File.CopyToAsync(fileStream);

                await fileStream.FlushAsync();

                propertyImage.File = fileStream.ToArray();
            }
            await _uow.CommitChangesAsync();

            return(await Task.FromResult(propertyImage.Oid));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddImagePropertyAsync([FromForm] ImagePropertyModelView imageProperty)
        {
            if (!TryValidateModel(imageProperty))
            {
                return(BadRequest(GetFullErrorMessage(ModelState)));
            }
            var idImageProperty = await _realEstateServices.AddImageProperty(imageProperty);

            return(Ok(idImageProperty));
        }
        public async Task AddImagePropertyTest()
        {
            RealEstateXPOServices realEstate = new RealEstateXPOServices(_uow);
            var fileStream = System.IO.File.OpenRead(@"TestImage\descargar.png");
            var property   = new ImagePropertyModelView {
                IdProperty = 1, File = new FormFile(fileStream, 0, fileStream.Length, "descargar", "descargar.png")
            };
            var result = await realEstate.AddImageProperty(property);

            fileStream.Close();
            Assert.IsTrue(result > 0);
        }
Ejemplo n.º 4
0
 public Task <int> AddImageProperty(ImagePropertyModelView imageProperty, CancellationToken token = default)
 {
     throw new NotImplementedException();
 }