예제 #1
0
      public async Task <IActionResult> AddImage(PropertyImageDto model)
      {
          if (ModelState.IsValid)
          {
              var path = string.Empty;

              if (model.ImageFile != null)
              {
                  path = await _imageHelper.UploadImageAsync(model.ImageFile);
              }

              var propertyImage = new PropertyImage
              {
                  ImageUrl = path,
                  Property = await _dataContext.Properties.FindAsync(model.Id)
              };

              _dataContext.PropertyImages.Add(propertyImage);
              await _dataContext.SaveChangesAsync();

              return(RedirectToAction($"{nameof(DetailsProperty)}/{model.Id}"));
          }

          return(View(model));
      }
예제 #2
0
        public async Task <PropertyDto> SaveData(int property, IFormFile formFile)
        {
            var propertyDto = await propertyRepository.FindById(property);

            if (propertyDto == null)
            {
                throw new Exception("Property Not Found");
            }
            var pi = new PropertyImageDto
            {
                Id       = 0,
                ImageUrl = await imageHelper.UploadImageAsync(formFile),
                Property = propertyDto
            };

            dataContext.PropertyImages.Add(pi);
            return(propertyDto);
        }
예제 #3
0
        public async Task <PropertyDto> SaveData(ImageRest imageRest)
        {
            var property = await propertyRepository.FindById(imageRest.PropertyId);

            if (property == null)
            {
                throw new Exception("Property Not Found");
            }
            var pi = new PropertyImageDto
            {
                Id       = imageRest.Id,
                ImageUrl = await imageHelper.UploadPhotoAsync(new MemoryStream(imageRest.ImageArray)),
                Property = property
            };

            dataContext.PropertyImages.Add(pi);
            await dataContext.SaveChangesAsync();

            return(property);
        }
예제 #4
0
      public async Task <IActionResult> AddImage(int?id)
      {
          if (id == null)
          {
              return(NotFound());
          }

          var property = await _dataContext.Properties.FindAsync(id.Value);

          if (property == null)
          {
              return(NotFound());
          }

          var model = new PropertyImageDto
          {
              Id = property.Id
          };

          return(View(model));
      }