protected override bool OnSaveToStorage(UsersModel model)
        {
            bool returnValue = false;
            USER user        = null;

            try
            {
                using (var db = new SearchHomeEntities())
                {
                    if (model.Id == 0)
                    {
                        user = new USER
                        {
                            UserId              = model.UserId,
                            UserName            = model.UserName,
                            UserImage           = model.ImagePath,
                            Degree              = model.Degree,
                            Interests           = model.Interests,
                            University          = model.University,
                            Status              = model.Status,
                            UserEmail           = model.Email,
                            LastUpdated         = DateTime.Now,
                            IsFirstTimeRegister = model.IsFirstTimeRegister
                        };
                        db.USERS.Add(user);
                    }
                    else
                    {
                        user                     = db.USERS.First(x => x.UserId == model.UserId);
                        user.UserId              = model.UserId;
                        user.UserName            = model.UserName;
                        user.University          = model.University;
                        user.Degree              = model.Degree;
                        user.Interests           = model.Interests;
                        user.Status              = model.Status;
                        user.UserEmail           = model.Email;
                        user.LastUpdated         = DateTime.Now;
                        user.IsFirstTimeRegister = model.IsFirstTimeRegister;
                        user.UserImage           = model.ImagePath;
                    }

                    if (returnValue = db.SaveChanges() > 0)
                    {
                        model.UserId = user.UserId;
                    }
                }
            }
            catch (Exception ex)
            {
                LogWriter.LogException("User Repository: ", ex);
            }

            return(returnValue);
        }
        protected override bool OnSaveToStorage(PropertyModel model)
        {
            bool     returnValue = false;
            Property property    = null;

            try
            {
                using (var db = new SearchHomeEntities())
                {
                    if (model.Id == 0)
                    {
                        property = new Property
                        {
                            PropertyName = model.PropertyName,
                            Address      = model.Address,
                            UserId       = model.UserId,
                            City         = model.City,
                            State        = model.State,
                            Details      = model.Details,
                            Amenities    = model.Amenities,
                            University   = model.University,
                            LastChange   = DateTime.Now
                        };
                        db.Properties.Add(property);
                    }
                    else
                    {
                        property = db.Properties.First(x => x.Id == model.Id);
                        property.PropertyName = model.PropertyName;
                        property.Address      = model.Address;
                        property.City         = model.City;
                        property.State        = model.State;
                        property.Details      = model.Details;
                        property.Amenities    = model.Amenities;
                        property.University   = model.University;
                        property.LastChange   = DateTime.Now;
                    }

                    if (returnValue = db.SaveChanges() > 0)
                    {
                        model.Id = property.Id;
                    }
                }
            }
            catch (Exception ex)
            {
                LogWriter.LogException("Property Repository: ", ex);
            }

            return(returnValue);
        }
        public bool SaveContextChanges(SearchHomeEntities context)
        {
            bool returnValue = false;

            if (context.ChangeTracker.HasChanges())
            {
                returnValue = context.SaveChanges() > 0;
            }
            else
            {
                returnValue = true;
            }
            return(returnValue);
        }
        public async Task <bool> DeleteUser(UsersModel model)
        {
            bool returnValue;

            using (var db = new SearchHomeEntities())
            {
                var user = db.USERS.Where(x => x.UserId == model.UserId).First();
                db.USERS.Remove(user);

                returnValue = db.SaveChanges() > 0;
            }

            return(await Task.FromResult(returnValue));
        }
        public bool UpdatePropertyImages(IEnumerable <PropertyImageModel> models, int propertyId)
        {
            bool returnValue = false;

            using (var db = new SearchHomeEntities())
            {
                var prop = db.PropertyImages.First(x => x.PropertyId == propertyId);

                foreach (var model in models)
                {
                    prop.ImagePath   = model.filePath;
                    prop.LastUpdated = DateTime.Now;
                }
                returnValue = db.SaveChanges() > 0;
            }
            return(returnValue);
        }
        public bool AddPropertyImages(IEnumerable <PropertyImageModel> models, int propertyId)
        {
            bool returnValue = false;

            using (var db = new SearchHomeEntities())
            {
                foreach (var model in models)
                {
                    var propertyImage = new PropertyImage
                    {
                        ImagePath  = model.filePath,
                        Name       = model.Name,
                        PropertyId = propertyId,
                        Size       = model.Size
                    };
                    db.PropertyImages.Add(propertyImage);
                }
                returnValue = db.SaveChanges() > 0;
            }
            return(returnValue);
        }
        protected override bool OnRemoveFromStorage(PropertyModel model)
        {
            bool returnValue;

            try
            {
                using (var db = new SearchHomeEntities())
                {
                    var propImage = db.PropertyImages.Where(x => x.PropertyId == model.Id);
                    db.PropertyImages.RemoveRange(propImage);

                    var property = db.Properties.Where(x => x.Id == model.Id).First();
                    db.Properties.Remove(property);

                    returnValue = db.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(returnValue);
        }
        public bool DeleteUserProperty(PropertyModel model)
        {
            bool returnValue = false;

            try
            {
                using (var db = new SearchHomeEntities())
                {
                    var propImg = db.PropertyImages.Where(x => x.Property.UserId == model.UserId);
                    db.PropertyImages.RemoveRange(propImg);

                    var properties = db.Properties.Where(x => x.UserId == model.UserId);
                    db.Properties.RemoveRange(properties);

                    returnValue = db.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(returnValue);
        }