Ejemplo n.º 1
0
        public PropertyModel GetSingleProperty(string MLS)
        {
            try
            {
                using (IDbConnection _db = OpenConnection())
                {
                    var perameters = new DynamicParameters();
                    perameters.Add("@MLSID_City_PostalCode", MLS);
                    perameters.Add("@MinPrice", '0');
                    perameters.Add("@MaxPrice", '0');
                    perameters.Add("@BathRooms", '0');
                    perameters.Add("@PropertyType", '0');
                    perameters.Add("@SaleLease", '0');
                    PropertyModel IdxCommercial = _db.Query <PropertyModel>("GetPropertyData_Comm", perameters, commandType: CommandType.StoredProcedure).FirstOrDefault();

                    try
                    {
                        string sourcePath;
                        var    ImageRootPath = @"C:\MlsData\";//ConfigurationManager.AppSettings["ImageURL"].ToString(); ;
                        if (IdxCommercial.VOX.ToString().ToLower() == "false")
                        {
                            sourcePath = ImageRootPath + "IDXImagesCommercial";
                        }
                        else
                        {
                            sourcePath = ImageRootPath + "VoxCommercial";
                        }
                        List <PropertyImages> imagelist = new List <PropertyImages>();
                        DirectoryInfo         dir       = new DirectoryInfo(sourcePath);
                        if (IdxCommercial != null)
                        {
                            foreach (FileInfo files in dir.GetFiles("Photo" + IdxCommercial.MLS.ToString() + "*.*"))
                            {
                                PropertyImages image = new PropertyImages();
                                image.MLS   = IdxCommercial.MLS.ToString();
                                image.Image = IdxCommercial.serverimagepath.ToString() + files.Name;
                                imagelist.Add(image);
                            }
                        }
                        IdxCommercial.PropertyImages = imagelist;
                        return(IdxCommercial);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }


                    return(IdxCommercial);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage GetPropertyByID([FromUri] int PropertyId)
        {
            try
            {
                if (PropertyId != 0)
                {
                    var Property = _PropertyService.GetProperty(PropertyId);
                    Mapper.CreateMap <CommunicationApp.Entity.Property, CommunicationApp.Web.Models.PropertyModel>();
                    CommunicationApp.Web.Models.PropertyModel PropertyModel = Mapper.Map <CommunicationApp.Entity.Property, CommunicationApp.Web.Models.PropertyModel>(Property);
                    var PropertyImages = _PropertyImageService.GetPropertyImages().Where(c => c.PropertyId == PropertyId);
                    List <PropertyImages> PropertyImageList = new List <PropertyImages>();
                    foreach (var propertyImage in PropertyImages)
                    {
                        PropertyImages PropertyImage = new PropertyImages();
                        PropertyImage.imagelist = propertyImage.ImagePath;
                        PropertyImageList.Add(PropertyImage);
                    }

                    PropertyModel.PropertyPhotolist = PropertyImageList;
                    var Customer = _CustomerService.GetCustomer(Convert.ToInt32(Property.CustomerId));
                    PropertyModel.CustomerName  = Customer.FirstName;
                    PropertyModel.CustomerPhoto = Customer.PhotoPath;
                    return(Request.CreateResponse(HttpStatusCode.OK, Common.CreateMessage("success", PropertyModel), Configuration.Formatters.JsonFormatter));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, Common.CreateMessage("error", "Property id null."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, Common.CreateMessage("error", "Property not found."), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Factory for creating Images
        /// </summary>
        /// <param name="imagesToAdd">images model to be added</param>
        /// <param name="imageType">PropertyImages/SightImages/UserImages/CityImages</param>
        public ISet <Images> CreateImagesFactory(ImageCreateViewModel imagesToAdd, string imageType, string userName)
        {
            string callerName;

            switch (imageType) // Caller Determining
            {
            case "PropertyImages":
                int propertyId = int.Parse(imagesToAdd.ForeignKey);
                callerName = unitOfWork.PropertiesRepository
                             .Where(p => p.Id == propertyId).Select(p => p.Owner.UserName)
                             .FirstOrDefault();
                //If property not found
                if (string.IsNullOrEmpty(callerName))
                {
                    throw new ArgumentException("No such Property");
                }
                break;

            case "SightImages":
                int sightId = int.Parse(imagesToAdd.ForeignKey);
                callerName = unitOfWork.SightsRepository
                             .Where(p => p.SightId == sightId).Select(p => p.SightName)
                             .FirstOrDefault();
                //If property not found
                if (string.IsNullOrEmpty(callerName))
                {
                    throw new ArgumentException("No such Sight");
                }
                break;

            case "UserImages":
                callerName = userName;
                //If property not found
                if (string.IsNullOrEmpty(callerName))
                {
                    throw new ArgumentException("No such user");
                }
                break;

            case "CityImages":
                int cityId = int.Parse(imagesToAdd.ForeignKey);
                callerName = unitOfWork.CitiesRepository
                             .Where(p => p.CityId == cityId).Select(p => p.CityName)
                             .FirstOrDefault();
                //If property not found
                if (string.IsNullOrEmpty(callerName))
                {
                    throw new ArgumentException("No such city");
                }
                break;

            default:
                throw new ArgumentException("No such image type");
            }

            ISet <Images> images = new HashSet <Images>();

            foreach (HttpPostedFileBase imageToAdd in imagesToAdd.ImageFiles)
            {
                Images image = null;
                switch (imageType)
                {
                case "PropertyImages":
                    image = new PropertyImages
                    {
                        ImagePath  = PathManager.CreateUserPropertyImagePath(callerName, imageToAdd.FileName),
                        PropertyId = int.Parse(imagesToAdd.ForeignKey)
                    };
                    break;

                case "SightImages":
                    image = new SightImages
                    {
                        ImagePath = PathManager.CreateSightImagePath(callerName, imageToAdd.FileName),
                        SightId   = int.Parse(imagesToAdd.ForeignKey)
                    };
                    break;

                case "UserImages":
                    image = new UserImages
                    {
                        ImagePath = PathManager.CreateUserProfileImagePath(callerName, imageToAdd.FileName),
                        UserId    = (string)imagesToAdd.ForeignKey
                    };
                    break;

                case "CityImages":
                    image = new CityImages
                    {
                        ImagePath = PathManager.CreateCityImagePath(callerName, imageToAdd.FileName),
                        CityId    = int.Parse(imagesToAdd.ForeignKey)
                    };
                    break;

                default:
                    throw new ArgumentException("No such image type");
                }
                image.ImageType = imageToAdd.ContentType;

                var physicalPath    = Path.Combine(HttpRuntime.AppDomainAppPath.TrimEnd('\\'), image.ImagePath.TrimStart('\\'));
                var physicalDirPath = Path.GetDirectoryName(physicalPath);
                if (!Directory.Exists(physicalDirPath))
                {
                    DirectoryHelpers.CreateDirectory(physicalDirPath);
                }
                imageToAdd.SaveAs(physicalPath);

                //Add Image to FileSystem
                Image img = Image.FromStream(imageToAdd.InputStream);
                image.ImageRatio = (float)img.Width / img.Height;

                //Adding image to DataBase
                unitOfWork.ImagesRepository.Add(image);
                unitOfWork.Save();

                //Add Image to returned set
                images.Add(image);
            }

            return(images);
        }
Ejemplo n.º 4
0
        public List <PropertyModel> GetPropertyList(List <Entity.Property> Properties)
        {
            List <PropertyModel> PropertyModelList = new List <PropertyModel>();

            Mapper.CreateMap <CommunicationApp.Entity.Property, CommunicationApp.Web.Models.PropertyModel>();
            foreach (var Property in Properties)
            {
                CommunicationApp.Web.Models.PropertyModel Propertymodel = Mapper.Map <CommunicationApp.Entity.Property, CommunicationApp.Web.Models.PropertyModel>(Property);
                var PropertyImages = _PropertyImageService.GetPropertyImages().Where(c => c.PropertyId == Property.PropertyId).ToList();


                // passing 'SaleOfBusinessType' to return model according to PropertyType.
                if (Property.PropertyStatusId != null)
                {
                    if (Property.PropertyStatusId == (int)EnumValue.PropertySatus.ExclusiveCommercial)
                    {
                        Propertymodel.TypeOfProperty = EnumValue.GetEnumDescription(EnumValue.PropertySatus.ExclusiveCommercial);
                    }
                    else if (Property.PropertyStatusId == (int)EnumValue.PropertySatus.ExclusiveResidential)
                    {
                        Propertymodel.TypeOfProperty = EnumValue.GetEnumDescription(EnumValue.PropertySatus.ExclusiveResidential);
                    }
                    else if (Property.PropertyStatusId == (int)EnumValue.PropertySatus.ExclusiveResidentialCondo)
                    {
                        Propertymodel.TypeOfProperty = EnumValue.GetEnumDescription(EnumValue.PropertySatus.ExclusiveResidentialCondo);
                    }
                    else if (Property.PropertyStatusId == (int)EnumValue.PropertySatus.LookingForCommercial)
                    {
                        Propertymodel.TypeOfProperty = EnumValue.GetEnumDescription(EnumValue.PropertySatus.LookingForCommercial);
                    }
                    else if (Property.PropertyStatusId == (int)EnumValue.PropertySatus.LookingForResidential)
                    {
                        Propertymodel.TypeOfProperty = EnumValue.GetEnumDescription(EnumValue.PropertySatus.LookingForResidential);
                    }
                    else if (Property.PropertyStatusId == (int)EnumValue.PropertySatus.LookingForResidentialCondo)
                    {
                        Propertymodel.TypeOfProperty = EnumValue.GetEnumDescription(EnumValue.PropertySatus.LookingForResidentialCondo);
                    }
                    else if (Property.PropertyStatusId == (int)EnumValue.PropertySatus.NewHotListingCommercial)
                    {
                        Propertymodel.TypeOfProperty = EnumValue.GetEnumDescription(EnumValue.PropertySatus.NewHotListingCommercial);
                    }
                    else if (Property.PropertyStatusId == (int)EnumValue.PropertySatus.NewHotListingResidential)
                    {
                        Propertymodel.TypeOfProperty = EnumValue.GetEnumDescription(EnumValue.PropertySatus.NewHotListingResidential);
                    }
                    else if (Property.PropertyStatusId == (int)EnumValue.PropertySatus.NewHotListingResidentialCondo)
                    {
                        Propertymodel.TypeOfProperty = EnumValue.GetEnumDescription(EnumValue.PropertySatus.NewHotListingResidentialCondo);
                    }
                }
                List <PropertyImages> PropertyImagesList = new List <PropertyImages>();
                foreach (var PropertyImage in PropertyImages)
                {
                    PropertyImages PropertyImg = new PropertyImages();
                    PropertyImg.imagelist = PropertyImage.ImagePath;
                    PropertyImagesList.Add(PropertyImg);
                }
                Propertymodel.PropertyPhotolist = PropertyImagesList;
                var customer = _CustomerService.GetCustomer(Convert.ToInt32(Property.CustomerId));
                Propertymodel.CustomerName   = customer.FirstName;
                Propertymodel.CustomerTrebId = customer.TrebId;
                Propertymodel.CustomerPhoto  = customer.PhotoPath;
                PropertyModelList.Add(Propertymodel);
            }

            return(PropertyModelList.ToList());
        }