public async Task <IHttpActionResult> PutPropertyPhoto(int id, PropertyPhoto propertyPhoto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != propertyPhoto.ImageID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult AddPhoto(int id, PropertyPhotoView file)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    PropertyPhoto model = new PropertyPhoto();
                    if (file != null)
                    {
                        model.PropertyId        = id;
                        model.Description       = file.Description;
                        model.Title             = file.Title;
                        model.PropertyPhotoPath = FileController.PostFile(file.PropertyPhotoPath, "propertyphotos", "propertyphotos");

                        //Call Post Method
                        APIMethods.APIPost <PropertyPhoto>(model, "PropertyPhotoes");
                        return(View());
                    }
                }
                catch (Exception E)
                {
                    throw new Exception(E.ToString());
                }



                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            PropertyPhoto propertyPhoto = await db.PropertyPhotos.FindAsync(id);

            db.PropertyPhotos.Remove(propertyPhoto);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IHttpActionResult> GetPropertyPhoto(int id)
        {
            PropertyPhoto propertyPhoto = await db.PropertyPhotos.FindAsync(id);

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

            return(Ok(propertyPhoto));
        }
        public async Task <ActionResult> Edit([Bind(Include = "ImageID,PropertyId,Title,Description,PropertyPhotoPath")] PropertyPhoto propertyPhoto)
        {
            if (ModelState.IsValid)
            {
                db.Entry(propertyPhoto).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.PropertyId = new SelectList(db.Properties, "PropertyID", "PropertyID", propertyPhoto.PropertyId);
            return(View(propertyPhoto));
        }
        public async Task <IHttpActionResult> PostPropertyPhoto(PropertyPhoto propertyPhoto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PropertyPhotos.Add(propertyPhoto);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = propertyPhoto.ImageID }, propertyPhoto));
        }
        public ActionResult _PhotoPartial(PropertyPhoto propertyPhoto)
        {
            if (ModelState.IsValid)
            {
                // NewPropView.PropertyPhotos.Add(propertyPhoto);

                return(PartialView());
            }
            else
            {
                return(PartialView());
            }
        }
        public async Task <ActionResult> Create([Bind(Include = "ImageID,PropertyId,Title,Description,PropertyPhotoPath")] PropertyPhoto propertyPhoto)
        {
            if (ModelState.IsValid)
            {
                db.PropertyPhotos.Add(propertyPhoto);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.PropertyId = new SelectList(db.Properties, "PropertyID", "PropertyID", propertyPhoto.PropertyId);
            return(View((object)propertyPhoto));
        }
        // GET: PropertyPhotoes/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PropertyPhoto propertyPhoto = await db.PropertyPhotos.FindAsync(id);

            if (propertyPhoto == null)
            {
                return(HttpNotFound());
            }
            return(View(propertyPhoto));
        }
        public async Task <IHttpActionResult> DeletePropertyPhoto(int id)
        {
            PropertyPhoto propertyPhoto = await db.PropertyPhotos.FindAsync(id);

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

            db.PropertyPhotos.Remove(propertyPhoto);
            await db.SaveChangesAsync();

            return(Ok(propertyPhoto));
        }
        // GET: PropertyPhotoes/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PropertyPhoto propertyPhoto = await db.PropertyPhotos.FindAsync(id);

            if (propertyPhoto == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PropertyId = new SelectList(db.Properties, "PropertyID", "PropertyID", propertyPhoto.PropertyId);
            return(View(propertyPhoto));
        }
Example #12
0
        private async Task <PropertyPhoto> UploadImage(IFormFile image)
        {
            if (image == null)
            {
                throw new ArgumentNullException();
            }

            using (var fileStream = image.OpenReadStream())
            {
                var imageExtension = Path.GetExtension(image.FileName);
                var imageUrl       = await _fileService.SaveFile(fileStream, imageExtension);

                var uploadedImage = new PropertyPhoto()
                {
                    Path = imageUrl.ToString()
                };
                return(uploadedImage);
            }
        }
Example #13
0
        public async Task <IHttpActionResult> GetPropertyPhoto(int id)
        {
            PropertyPhoto objct = await db.PropertyPhotos.FindAsync(id);

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

            PropertyPhotoNoR newObject = new PropertyPhotoNoR()
            {
                Description       = objct.Description,
                ImageID           = objct.ImageID,
                PropertyId        = objct.PropertyId,
                PropertyPhotoPath = objct.PropertyPhotoPath,
                //   PropertyNoR = objct.PropertyNoR,
                Title = objct.Title
            };

            return(Ok(newObject));
        }
Example #14
0
        public IActionResult Edit(ListingViewModel listingViewModel, int Id)
        {
            var minNights = 0;
            var maxNights = 0;

            if (listingViewModel.MinNights != null)
            {
                minNights = int.Parse(listingViewModel.MinNights.Split(' ')[0]);
            }
            else
            {
                minNights = 0;
            }
            if (listingViewModel.MaxNights != null)
            {
                maxNights = int.Parse(listingViewModel.MaxNights.Split(' ')[0]);
            }
            else
            {
                maxNights = 0;
            }
            var name           = _db.Categories.FirstOrDefault(x => x.Name == listingViewModel.Categoryname);
            var id             = name.Id;
            var guestPlaceType = _db.GuestPlaceTypes.FirstOrDefault(x => x.Name == listingViewModel.GuestPlaceTypeName);
            var PlaceTypeId    = guestPlaceType.Id;
            var NewProperty    = _db.Properties.FirstOrDefault(x => x.Id == Id);

            NewProperty.CategoryId        = id;
            NewProperty.GuestPlaceTypeId  = PlaceTypeId;
            NewProperty.NumberOfBedRooms  = int.Parse(listingViewModel.NumOfBedrooms);
            NewProperty.NumberOfBeds      = listingViewModel.NumOfBeds;
            NewProperty.Zipcode           = listingViewModel.ZipCode;
            NewProperty.BuildingNo        = listingViewModel.Apt_Suite;
            NewProperty.Street            = listingViewModel.Street;
            NewProperty.Title             = listingViewModel.Title;
            NewProperty.Description       = listingViewModel.Description;
            NewProperty.NumberOfBathrooms = listingViewModel.NumberOfBathRooms;
            NewProperty.MinStay           = minNights;
            NewProperty.MaxStay           = maxNights;
            NewProperty.Price             = listingViewModel.Price;
            NewProperty.Capacity          = listingViewModel.NumOfGuests;
            NewProperty.CityId            = listingViewModel.CityId;
            NewProperty.Coordinates       = new NetTopologySuite.Geometries.Point(listingViewModel.Lon, listingViewModel.Lat)
            {
                SRID = 4326
            };
            NewProperty.UserId = _manager.GetUserId(User);
            _db.SaveChanges();
            string UniqueFileName = null;

            if (listingViewModel.Images != null)
            {
                for (var i = 0; i < listingViewModel.Images.Count; i++)
                {
                    string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "Images");
                    UniqueFileName = Guid.NewGuid().ToString() + "_" + listingViewModel.Images[i].FileName;
                    string FilePath = Path.Combine(uploadsFolder, UniqueFileName);
                    listingViewModel.Images[i].CopyTo(new FileStream(FilePath, FileMode.Create));
                    PropertyPhoto photo = new PropertyPhoto();
                    photo.PropertyId = NewProperty.Id;
                    photo.Url        = UniqueFileName;
                    //_db.Ed(photo);
                    _db.SaveChanges();
                }
            }
            //amenty
            if (listingViewModel.IsChecked != null)
            {
                foreach (var item in listingViewModel.IsChecked)
                {
                    PropertyAmenity amenity = new PropertyAmenity();
                    amenity.AmenityId  = item;
                    amenity.PropertyId = NewProperty.Id;
                    //_db.Add(amenity);
                    _db.SaveChanges();
                }
            }
            //SpacesCanGuestUse
            if (listingViewModel.IsSpacesChecked != null)
            {
                foreach (var item in listingViewModel.IsSpacesChecked)
                {
                    PropertySpace propertySpace = new PropertySpace();
                    propertySpace.PropertyId = NewProperty.Id;
                    propertySpace.SpaceId    = item;
                    //_db.Add(propertySpace);
                    _db.SaveChanges();
                }
            }
            //HouseRoles
            if (listingViewModel.IsHouseRoleChecked != null)
            {
                foreach (var item in listingViewModel.IsHouseRoleChecked)
                {
                    PropertyHouseRule propertyHouseRule = new PropertyHouseRule();
                    propertyHouseRule.PropertyId  = NewProperty.Id;
                    propertyHouseRule.HouseRuleId = item;
                    //_db.Add(propertyHouseRule);
                    _db.SaveChanges();
                }
            }
            return(RedirectToAction("Listing", "Hosting"));
        }
Example #15
0
        private void AddPhoto()
        {
            if (fudProPertyImage.HasFile)
            {
                List <PropertyPhoto> objPropertyPhotoList = null;
                string path = null;
                objUserDetail = (UserDetail)SessionUtility.SessionUtility.AmsSessionContainer.OBJ_USER_CLASS;
                if (SessionUtility.SessionUtility.AmsSessionContainer.OBJ_Photo_CLASS == null)
                {
                    objPropertyPhotoList = new List <PropertyPhoto>();
                }
                else
                {
                    objPropertyPhotoList = SessionUtility.SessionUtility.AmsSessionContainer.OBJ_Photo_CLASS as List <PropertyPhoto>;
                }



                //string theFileName = DateTime.Now.ToShortDateString() + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Millisecond + "-" + fudPropertyPhoto.FileName;
                //string path = FolderPath + theFileName;
                string folderPath    = ConfigurationManager.AppSettings["ProfileImageUrl"];
                string directoryPath = Server.MapPath(folderPath + "/" + objUserDetail.UserID.Trim() + "/ImgTemp");
                string extension     = Path.GetExtension(fudProPertyImage.FileName).ToLower();

                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                if (extension != null)
                {
                    path = directoryPath + "/" + fudProPertyImage.FileName;


                    if (File.Exists(Server.MapPath(path)))
                    {
                        File.Delete(Server.MapPath(path));
                    }
                    objUserDetail.ProfileImageUrl = path;
                    fudProPertyImage.SaveAs(Server.MapPath(path));
                }

                PropertyPhoto objPropertyPhoto = new PropertyPhoto();
                objPropertyPhoto.PropertyPhotoSerial = objPropertyPhotoList.Count + 1;
                objPropertyPhoto.PhotoName           = fudProPertyImage.FileName;
                objPropertyPhoto.PhotoUrl            = path;


                objPropertyPhotoList.Add(objPropertyPhoto);
                SessionUtility.SessionUtility.AmsSessionContainer.OBJ_Photo_CLASS = objPropertyPhotoList;
            }

            else
            {
                MessageBox("Please upload a file.");
            }
            if (SessionUtility.SessionUtility.AmsSessionContainer.OBJ_Photo_CLASS != null)
            {
                List <PropertyPhoto> objPropertyPhotoList = SessionUtility.SessionUtility.AmsSessionContainer.OBJ_Photo_CLASS as List <PropertyPhoto>;
                foreach (PropertyPhoto objProperty in objPropertyPhotoList)
                {
                    imgPropertyPhotoTemp.ImageUrl = objProperty.PhotoUrl;
                }
            }
        }
Example #16
0
        public ActionResult FileUpload(PropertyPhoto Details,
                                       HttpPostedFileBase File1, HttpPostedFileBase File2, HttpPostedFileBase File3, HttpPostedFileBase File4
                                       , HttpPostedFileBase File5, HttpPostedFileBase File6, HttpPostedFileBase File7, HttpPostedFileBase File8
                                       , HttpPostedFileBase File9, HttpPostedFileBase File10)
        {
            var db = new ApnuGharEntities();

            if (File1 != null && File1.ContentLength > 0)
            {
                Details.Image = new byte[File1.ContentLength]; // file1 to store image in binary formate
                File1.InputStream.Read(Details.Image, 0, File1.ContentLength);
                Details.PropertyId = 1;
                string ImageName = System.IO.Path.GetFileName(File2.FileName); //file2 to store path and url
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            if (File2 != null && File2.ContentLength > 0)
            {
                Details.Image = new byte[File2.ContentLength]; // file1 to store image in binary formate
                File2.InputStream.Read(Details.Image, 0, File2.ContentLength);
                Details.PropertyId = 1;
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            if (File3 != null && File3.ContentLength > 0)
            {
                Details.Image = new byte[File3.ContentLength]; // file1 to store image in binary formate
                File3.InputStream.Read(Details.Image, 0, File3.ContentLength);
                Details.PropertyId = 1;
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            if (File4 != null && File4.ContentLength > 0)
            {
                Details.Image = new byte[File4.ContentLength]; // file1 to store image in binary formate
                File4.InputStream.Read(Details.Image, 0, File4.ContentLength);
                Details.PropertyId = 1;
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            if (File5 != null && File5.ContentLength > 0)
            {
                Details.Image = new byte[File5.ContentLength]; // file1 to store image in binary formate
                File5.InputStream.Read(Details.Image, 0, File5.ContentLength);
                Details.PropertyId = 1;
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            if (File6 != null && File6.ContentLength > 0)
            {
                Details.Image = new byte[File6.ContentLength]; // file1 to store image in binary formate
                File6.InputStream.Read(Details.Image, 0, File6.ContentLength);
                Details.PropertyId = 1;
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            if (File7 != null && File7.ContentLength > 0)
            {
                Details.Image = new byte[File7.ContentLength]; // file1 to store image in binary formate
                File7.InputStream.Read(Details.Image, 0, File7.ContentLength);
                Details.PropertyId = 1;
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            if (File8 != null && File8.ContentLength > 0)
            {
                Details.Image = new byte[File8.ContentLength]; // file1 to store image in binary formate
                File8.InputStream.Read(Details.Image, 0, File8.ContentLength);
                Details.PropertyId = 1;
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            if (File9 != null && File9.ContentLength > 0)
            {
                Details.Image = new byte[File9.ContentLength]; // file1 to store image in binary formate
                File9.InputStream.Read(Details.Image, 0, File9.ContentLength);
                Details.PropertyId = 1;
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            if (File10 != null && File10.ContentLength > 0)
            {
                Details.Image = new byte[File10.ContentLength]; // file1 to store image in binary formate
                File10.InputStream.Read(Details.Image, 0, File10.ContentLength);
                Details.PropertyId = 1;
                db.PropertyPhotos.Add(Details);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Example #17
0
        private async Task DeleteImage(PropertyPhoto photo)
        {
            await DeleteImageFile(photo.Path);

            _unitOfWork.Repository <PropertyPhoto>().Remove(photo);
        }