예제 #1
0
        public int AddProperty(Property p)
        {
            int propertyId;


            using (var context = new RealEstateDataLayer.RealEstateEntities())
            {
                context.ContextOptions.LazyLoadingEnabled = false;
                context.Properties.AddObject(p);

                context.SaveChanges();
                propertyId = p.PropertyId;
            }


            return(propertyId);
        }
예제 #2
0
        /// <summary>
        /// This method deletes a properties.
        /// </summary>
        /// <param name="propertyid"></param>
        /// <returns></returns>
        public bool DeleteProperty(int propertyid)
        {
            bool result = false;

            using (var context = new RealEstateDataLayer.RealEstateEntities())
            {
                context.ContextOptions.LazyLoadingEnabled = false;
                Property original = context.Properties.Where(o => o.PropertyId == propertyid).Select(o => o).FirstOrDefault();

                List <Picture> lstP = context.Pictures.Where(p => p.PropertyId == propertyid).Select(p => p).ToList();
                foreach (Picture p in lstP)
                {
                    context.Pictures.DeleteObject(p);
                }
                context.Properties.DeleteObject(original);
                context.SaveChanges();
                result = true;
            }
            return(result);
        }
예제 #3
0
        public bool SaveImage(Picture p)
        {
            bool result = false;

            try
            {
                using (var context = new RealEstateDataLayer.RealEstateEntities())
                {
                    context.ContextOptions.LazyLoadingEnabled = false;
                    //Update
                    if (p.PictureId != 0)
                    {
                        var modPic = context.Pictures.Where(s => s.PictureId == p.PictureId).Select(s => s).FirstOrDefault();
                        modPic.IsMain = p.IsMain;
                        modPic.Show   = p.Show;
                        modPic.Order  = p.Order;
                    }
                    //create a new picture
                    else
                    {
                        var countMain = context.Pictures.Where(s => s.PropertyId == p.PropertyId).Select(s => s.IsMain == true);
                        if (countMain.Count() == 0)
                        {
                            p.IsMain = true;
                        }
                        p.Show  = true;
                        p.Order = context.Pictures.Where(s => s.PropertyId == p.PropertyId).Count() + 1;
                        context.Pictures.AddObject(p);
                    }
                    result = true;

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// This method deletes the Image according to the picture Id
        /// </summary>
        /// <param name="PictureId"></param>
        /// <returns></returns>
        public bool DeleteImage(int PictureId)
        {
            bool result = false;

            try
            {
                using (var context = new RealEstateDataLayer.RealEstateEntities())
                {
                    context.ContextOptions.LazyLoadingEnabled = false;
                    var delPic = context.Pictures.Where(s => s.PictureId == PictureId).Select(s => s).FirstOrDefault();
                    context.Pictures.DeleteObject(delPic);
                    result = true;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
예제 #5
0
        public void UpdateProperty(Property p)
        {
            using (var context = new RealEstateDataLayer.RealEstateEntities())
            {
                context.ContextOptions.LazyLoadingEnabled = false;
                Property original = context.Properties.Where(o => o.PropertyId == p.PropertyId).Select(o => o).FirstOrDefault();

                if (p.MLSId != original.MLSId)
                {
                    original.MLSId = p.MLSId;
                }

                if (p.Baths != original.Baths)
                {
                    original.Baths = p.Baths;
                }

                if (p.Beds != original.Beds)
                {
                    original.Beds = p.Beds;
                }

                if (p.Price != original.Price)
                {
                    original.Price = p.Price;
                }

                if (p.StatusId != original.StatusId)
                {
                    original.StatusId = p.StatusId;
                }

                if (p.StreetAddress != original.StreetAddress)
                {
                    original.StreetAddress = p.StreetAddress;
                }

                if (p.Country != original.Country)
                {
                    original.Country = p.Country;
                }

                if (p.StateProvince != original.StateProvince)
                {
                    original.StateProvince = p.StateProvince;
                }

                if (p.City != original.City)
                {
                    original.City = p.City;
                }

                if (p.PostalCode != original.PostalCode)
                {
                    original.PostalCode = p.PostalCode;
                }

                if (p.Location != original.Location)
                {
                    original.Location = p.Location;
                }

                if (p.MLSUrl != original.MLSUrl)
                {
                    original.MLSUrl = p.MLSUrl;
                }

                if (p.VirtualTourUrl != original.VirtualTourUrl)
                {
                    original.VirtualTourUrl = p.VirtualTourUrl;
                }

                if (p.Description != original.Description)
                {
                    original.Description = p.Description;
                }

                context.SaveChanges();
            }
        }