Beispiel #1
0
        public async Task DeleteImageAsync(string id)
        {
            string filePath = _hostingEnvironment.ContentRootPath + "\\Contents";


            // Get the image by id, then URL, then the filename in the URL path

            var imgId = new ObjectId(id);

            PropertyImage img = await _imageRepository.GetImage(imgId);

            int start = img.Url.LastIndexOf("/");

            string fName = img.Url.Substring(start + 1);


            try
            {
                await _imageRepository.RemoveImage(imgId);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            string f = filePath + "\\" + fName;

            System.IO.File.Delete(f); // Delete the file from storage
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("FileName,FilePath,FileType,Id,CreatedDate,UpdatedDate")] PropertyImage propertyImage)
        {
            if (id != propertyImage.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(propertyImage);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PropertyImageExists(propertyImage.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(propertyImage));
        }
Beispiel #3
0
        public async Task <IActionResult> UploadImage(IFormFile file, PropertyImage image)// [FromBody] PropertyImage image)    //public async Task<IActionResult> UploadImage(IFormFile file, string id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            if (file == null || file.Length == 0)
            {
                return(Content("file not selected"));
            }

            string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\");

            using (var fs = new FileStream(Path.Combine(path, file.FileName), FileMode.Create))
            {
                await file.CopyToAsync(fs);

                // Add image path to DB

                await _imageRepository.AddImageAsync(new PropertyImage
                {
                    //Url = "~/Contents/" + file.FileName, // Path.Combine(path, file.FileName),
                    Url        = "images/" + file.FileName,
                    Caption    = "First image for the property",
                    PropertyId = image.PropertyId, // "62541",
                    DateAdded  = DateTime.Now
                });
            }

            return(Content("file uploaded"));
        }
        public async Task <PropertyImage> DeletePropertyImage(PropertyImage propertyImage)
        {
            _unitOfWork.PropertyImages.RemoveAsync(propertyImage);
            await _unitOfWork.CommitAsync();

            return(propertyImage);
        }
Beispiel #5
0
        public async Task <IActionResult> AddImage(PropertyImageViewModel 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));
        }
Beispiel #6
0
        async Task <List <PropertyImageResponse> > IRequestHandler <CreatePropertyImageRangeCommand, List <PropertyImageResponse> > .Handle(
            CreatePropertyImageRangeCommand request,
            CancellationToken cancellationToken)
        {
            var images = new List <PropertyImage>();

            foreach (var file in request.Images)
            {
                var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');

                using var memoryStream = new MemoryStream();

                await file.CopyToAsync(memoryStream);

                var propertyImage = new PropertyImage()
                {
                    Image      = memoryStream.ToArray(),
                    PropertyId = request.PropertyId
                };

                images.Add(propertyImage);

                await _propertyImagesService.CreateAsync(propertyImage);
            }

            return(_mapper.Map <List <PropertyImage>, List <PropertyImageResponse> >(images));
        }
        public async Task <PropertyImage> ToggleMainImageState(PropertyImage propertyImage)
        {
            propertyImage.IsMain = !propertyImage.IsMain;
            await _unitOfWork.CommitAsync();

            return(propertyImage);
        }
        public async Task <PropertyImage> CreatePropertyImage(PropertyImage propertyImage)
        {
            _context.PropertyImages.Add(propertyImage);
            await _context.SaveChangesAsync();

            return(propertyImage);
        }
 public ActionResult AddProperty([Bind(Include = "PropertyId,Title,Detail,Price,Area,RoomNumber,FloorNumber,TotalFloor,HeatingSystem,BuildingAge,Country,City, State, Address")] Property property)
 {
     if (ModelState.IsValid)
     {
         List <PropertyImage> propertyImageList = new List <PropertyImage>();
         for (int i = 0; i < Request.Files.Count; i++)
         {
             var file = Request.Files[i];
             if (file != null && file.ContentLength > 0)
             {
                 var           filename      = Path.GetFileName(file.FileName);
                 PropertyImage propertyImage = new PropertyImage()
                 {
                     ImageName  = filename,
                     Extenstion = Path.GetExtension(filename),
                     Guid       = Guid.NewGuid()
                 };
                 propertyImageList.Add(propertyImage);
                 var path = Path.Combine(Server.MapPath("~/Images/Property"), propertyImage.Guid + propertyImage.Extenstion);
                 file.SaveAs(path);
             }
         }
         property.PropertyImages = propertyImageList;
         property.Date           = DateTime.Now;
         db.Properties.Add(property);
         db.SaveChanges();
         TempData["message"] = string.Format("Property added successfully");
         return(RedirectToAction("PropertyList"));
     }
     return(View());
 }
        public async Task <PropertyImage> UpdatePropertyImage(PropertyImage propertyImage)
        {
            _context.Entry(propertyImage).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(propertyImage);
        }
Beispiel #11
0
        public async Task <ICollection <PropertyImageViewModel> > UploadAsync(ICollection <IFormFile> files, Guid portfolioId, Guid propertyId)
        {
            var result = new List <PropertyImageViewModel>();

            var resources = await files.ProcessResourcesAsync(HostingEnvironment.WebRootPath, portfolioId.ToString());

            if (resources == null)
            {
                return(null);
            }

            foreach (var resource in resources)
            {
                var entity = new PropertyImage
                {
                    PropertyId = propertyId,
                    FileName   = resource.FileName,
                    Created    = DateTime.Now
                };

                await Context.PropertyImages.AddAsync(entity);

                await Context.SaveChangesAsync();

                result.Add(new PropertyImageViewModel(entity));
            }

            return(result);
        }
        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));
        }
        /// <summary>
        /// associates the image with the property that was uploaded
        /// </summary>
        /// <param name="file"></param>
        private void associateImagesWithProperty(UnitOfWork unitOfWork, HttpPostedFileBase[] files, Guid propertyID)
        {
            bool isPrimaryDisplay = true;//the first uploaded will be selected as the primary display

            foreach (var file in files)
            {
                string fileName = string.Empty;

                Guid guid = Guid.NewGuid();

                fileName = guid.ToString() + Path.GetExtension(file.FileName);

                PropertyImage propertyImage = new PropertyImage()
                {
                    ID               = guid,
                    PropertyID       = propertyID,
                    ImageURL         = fileName,
                    IsPrimaryDisplay = isPrimaryDisplay,
                    DateTCreated     = DateTime.Now
                };

                if (isPrimaryDisplay == true)
                {
                    isPrimaryDisplay = false;
                }

                unitOfWork.PropertyImage.Add(propertyImage);

                uploadPropertyImages(file, fileName);
            }
        }
        public async Task <IActionResult> AddImage(PropertyImageViewModel model)
        {
            //Validamos si el modelo es válido
            if (ModelState.IsValid)
            {
                //creamos la variable path asumiendo que adiciono la imagen
                string path = string.Empty;

                //Imagefile=Iformfile donde se captura la imagen
                //Si hay una imagen
                if (model.ImageFile != null)
                {
                    //Llamamos al método que creamos en la interface para subir la imagen
                    //nos devuelve la ruta de como se va ha guradar en la bd
                    path = await _imageHelper.UploadImageAsync(model.ImageFile);
                }

                //Creamos el objeto PropertyImage
                PropertyImage propertyImage = new PropertyImage
                {
                    ImageUrl = path,//Es la ruta que nos devovlio del método en la interface
                    //buscamos el objeto con el id, ya que desde el get no lo podemos enviar
                    Property = await _dataContext.Properties.FindAsync(model.Id)
                };

                //Finalmente guardamos en la coleccion de imagenes la propertyImage
                //retornamos al detailsProperty con el id de la propiedad
                _dataContext.PropertyImages.Add(propertyImage);
                await _dataContext.SaveChangesAsync();

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

            return(View(model));
        }
        public async Task <IHttpActionResult> PutPropertyImage(int id, PropertyImage propertyImage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != propertyImage.ID)
            {
                return(BadRequest());
            }

            db.Entry(propertyImage).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PropertyImageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #16
0
        public async Task <bool> CreateAsync(PropertyImage propertyImage)
        {
            await _dataContext.PropertyImages.AddAsync(propertyImage);

            var created = await _dataContext.SaveChangesAsync();

            return(created > 0);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            PropertyImage propertyImage = db.PropertyImages.Find(id);

            db.PropertyImages.Remove(propertyImage);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #18
0
 public PropertyDescription(Form form, Property property)
 {
     InitializeComponent();
     this.form          = form;
     this.property      = property;
     this.propertyImage = new PropertyImage();
     this.pd            = new Entites.PropertyDescription();
     this.da            = new DataAccess();
 }
Beispiel #19
0
        public void SaveData(Property item, PropertyImageCollection imageCol)
        {
            item.AddUpdate();
            PropertyImage img = new PropertyImage();

            img.PRL = item.PRL;
            img.DeleteByPRL();
            img.Add(imageCol);
        }
 public IActionResult Post([FromBody] PropertyImage propertyImage)
 {
     using (var scope = new TransactionScope())
     {
         _Repo.Insert(propertyImage);
         scope.Complete();
         return(CreatedAtAction(nameof(Get), new { id = propertyImage.Id }, propertyImage));
     }
 }
        public void AddPropertyImage(PropertyImage propertyImage)
        {
            if (propertyImage == null)
            {
                throw new ArgumentNullException(nameof(propertyImage));
            }

            _context.PropertyImage.Add(propertyImage);
        }
Beispiel #22
0
        public PropertyImage AddPropertyImage(int propertyId, string path)
        {
            PropertyImage propertyImage = new PropertyImage();

            propertyImage.PropertyId = propertyId;
            propertyImage.ImagePath  = path;
            _db.PropertyImages.Add(propertyImage);
            _db.SaveChanges();
            return(propertyImage);
        }
Beispiel #23
0
      public ActionResult AddPictureProperty(PropertyImage pic)
      {
          if (pic.image != null)
          {
              db.PropertyImages.Add(pic);
              db.SaveChanges();
          }

          return(RedirectToAction("Index"));
      }
Beispiel #24
0
        public void DeleteData(string prl)
        {
            PropertyImage img = new PropertyImage();

            img.PRL = prl;
            img.DeleteByPRL();
            Property property = new Property();

            property.DeleteByPRL(prl);
        }
Beispiel #25
0
        public ActionResult Edit(Property property, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                try {
                    property.DateAdded = DateTime.Now;
                    unitOfWork.PropertyRepository.Update(property);
                    unitOfWork.AddressRepository.Update(property.Address);



                    int count = 0;

                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            if (file.ContentLength > 0)
                            {
                                var fileName = Path.GetFileName(file.FileName);
                                var path     = Path.Combine(Server.MapPath("~/Images/user_uploads/" + User.Identity.Name), fileName);
                                file.SaveAs(path);
                                PropertyImage propertyImage = new PropertyImage();
                                propertyImage.url         = "~/Images/user_uploads/" + User.Identity.Name + "/" + fileName;
                                propertyImage.description = "Proba";
                                //unitOfWork.PropertyImageRepository.Insert(propertyImage);

                                property.propertyImages.Add(propertyImage);
                                count++;
                            }
                        }
                    }

                    if (count == 0)
                    {
                        PropertyImage propertyImage = new PropertyImage();
                        propertyImage.url         = "~/Images/default.jpg";
                        propertyImage.description = "Proba";
                        //unitOfWork.PropertyImageRepository.Insert(propertyImage);

                        property.propertyImages.Add(propertyImage);
                    }


                    unitOfWork.Save();
                }
                catch (Exception e)
                {
                    return(View(property));
                }

                return(View("Details", property));
            }
            return(View(property));
        }
Beispiel #26
0
        public ActionResult <PropertyImageDTO> AddPropertyImage([FromBody] PropertyImageDTO propertyImageCreation)
        {
            PropertyImage propertyImage = _mapper.Map <PropertyImage>(propertyImageCreation);

            _realStateAPIRepository.AddPropertyImage(propertyImage);
            _realStateAPIRepository.Save();

            PropertyImageDTO propertyImageDTO = _mapper.Map <PropertyImageDTO>(propertyImage);

            return(new CreatedAtRouteResult("GetPropertyImageById", new { idPropertyImage = propertyImage.IdPropertyImage }, propertyImageDTO));
        }
Beispiel #27
0
        public IActionResult Post([FromBody] PropertyImage image)
        {
            var    imageFromDb = _repository.GetPropertyImage(image.Id);
            string webRootPath = _hostingEnvironment.WebRootPath;
            //change from explorer path to url path
            var imagePath = imageFromDb.ImagePath.Replace('/', '\\');
            var fullPath  = Path.Combine(webRootPath, "uploads", imagePath);

            _repository.DeletePropertyImage(imageFromDb, fullPath);
            return(StatusCode(202));
        }
Beispiel #28
0
        public string DeletePropertyImage(PropertyImage image, string fileName)
        {
            if (System.IO.File.Exists(fileName))
            {
                System.IO.File.Delete(fileName);
            }

            _db.PropertyImages.Remove(image);
            _db.SaveChanges();
            return("File Deleted");
        }
Beispiel #29
0
        public PropertyImageViewModel(PropertyImage propertyImage)
        {
            if (propertyImage == null)
            {
                throw new ArgumentNullException(nameof(propertyImage));
            }

            FileName   = propertyImage.FileName;
            PropertyId = propertyImage.PropertyId;
            Id         = propertyImage.Id;
        }
 public ActionResult Edit([Bind(Include = "Id,Name,PropertyId")] PropertyImage propertyImage)
 {
     if (ModelState.IsValid)
     {
         db.Entry(propertyImage).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PropertyId = new SelectList(db.Properties, "Id", "Name", propertyImage.PropertyId);
     return(View(propertyImage));
 }