/// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        public void DeleteLocationIndoor(LocationIndoor obj)
        {
            var meta = DeleteLocationIndoorAuthorization(obj);

            locIndoorRepo.Delete(obj.ID);

            //-- Update the cache
            AppLookups.RemoveCacheIndexEntry(obj.ID);

            var modWhoAddedArea = modProfileRepo.GetByID(meta.CreatedByUserID);

            if (modWhoAddedArea.PlacesAdded > 0)
            {
                modWhoAddedArea.PlacesAdded--;
                modProfileRepo.Update(modWhoAddedArea);

                //-- Remove the points associated with this place
                var actionsWithPoints = modActionRepo.GetAll().Where(a => a.OnObjectID == meta.ID);
                ReverseActions(actionsWithPoints);
            }

            //-- update the principal details with the details we just updated (if they are the same person who deleted it)
            CfPrincipal.AttachModProfile(modProfileRepo.GetByID(currentUser.UserID));

            //-- Incase the name changed during the life of the object, we want to save the meta with the same name as the object was when it was deleted.
            meta.Name = obj.VerboseDisplayName;

            var action = SaveModActionAndUpdateModProfile(ModActionType.LocationIndoorDelete, obj, null, meta,
                                                          (m, actionID) => m.SetDeleted(actionID), null, "deleted {0} {1}", obj.Type, obj.Name);

            postSvc.DeleteContentAddPost(action);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public LocationIndoor CreateLocationIndoor(LocationIndoor obj)
        {
            var user = CfPerfCache.GetClimber(CfIdentity.UserID);

            CreateLocationIndoorAuthorization(obj);

            obj.NameUrlPart = obj.Name.ToUrlFriendlyString();

            locIndoorRepo.Create(obj);
            var meta = objModMetaRepo.Create(new ObjectModMeta(obj, currentUser.UserID));

            //-- Refresh the cache
            AppLookups.AddIndexEntryToCache( obj.ToCacheIndexEntry() );

            ClaimObject(obj);

            //-- Save post for the feed
            //PostService.CreateLocationCreatedPost(obj);

            var action = SaveModActionAndUpdateModProfile(ModActionType.LocationIndoorAdd, null, obj, meta,
                (m, actionID) => m.SetCreated(actionID), mp => mp.PlacesAdded++, "added {0} {1}", obj.Type, obj.Name);

            postSvc.CreateContentAddPost(action, obj.ID, user.PrivacyPostsDefaultIsPublic);
            //-- TODO: Calculate all areas that completely contain this area + Shoot off a notification to moderators

            return obj;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public LocationIndoor CreateLocationIndoor(LocationIndoor obj)
        {
            var user = CfPerfCache.GetClimber(CfIdentity.UserID);

            CreateLocationIndoorAuthorization(obj);

            obj.NameUrlPart = obj.Name.ToUrlFriendlyString();

            locIndoorRepo.Create(obj);
            var meta = objModMetaRepo.Create(new ObjectModMeta(obj, currentUser.UserID));

            //-- Refresh the cache
            AppLookups.AddIndexEntryToCache(obj.ToCacheIndexEntry());

            ClaimObject(obj);

            //-- Save post for the feed
            //PostService.CreateLocationCreatedPost(obj);

            var action = SaveModActionAndUpdateModProfile(ModActionType.LocationIndoorAdd, null, obj, meta,
                                                          (m, actionID) => m.SetCreated(actionID), mp => mp.PlacesAdded++, "added {0} {1}", obj.Type, obj.Name);

            postSvc.CreateContentAddPost(action, obj.ID, user.PrivacyPostsDefaultIsPublic);
            //-- TODO: Calculate all areas that completely contain this area + Shoot off a notification to moderators

            return(obj);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="original"></param>
        /// <param name="updated"></param>
        /// <returns></returns>
        ObjectModMeta UpdateLocationIndoorAuthorization(LocationIndoor original, LocationIndoor updated)
        {
            var meta = SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(original);

            if (original.ID != updated.ID || original.CountryID != updated.CountryID)
            {
                throw new ArgumentException(string.Format("Original indoor location {0}[{1}][{2}] is not the same as updated {3}[{4}][{5}]",
                                                          original.Name, original.CountryID, original.ID, updated.Name, updated.CountryID, updated.ID));
            }

            if ((original.Latitude != updated.Latitude) || (original.Longitude != updated.Longitude))
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the position of a verified outdoor location.");
                }
            }

            if ((original.Name != updated.Name))
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the name of an outdoor location that has already been verified.");
                }
            }

            if ((original.NameUrlPart != updated.NameUrlPart))
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the url.");
                }
            }

            if ((original.Description != updated.Description) && meta.CQR > 6)
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the description of an outdoor location that has been verified and has a high CQR.");
                }
            }

            if (original.Address != updated.Address)
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the address.");
                }
            }

            if (original.Website != updated.Website)
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the website.");
                }
            }

            return(meta);
        }
Exemplo n.º 5
0
        private void SetLocationIndoorEditViewData(LocationIndoor location)
        {
            ViewBag.Location = location;
            ViewBag.LogoImageToDisplayUrl = (location.HasLogo) ? Stgs.ImgsRt + location.LogoRelativeUrl : Stgs.DefaultMapInfoImage;
            var climbImageToDisplay = (location.HasAvatar) ? Stgs.ImgsRt + location.AvatarRelativeUrl : Stgs.DefaultMapInfoImage;

            ViewBag.ClimbingImageToDisplayUrl = climbImageToDisplay;
        }
        ObjectModMeta SaveLocationIndoorLogoAuthorization(LocationIndoor obj, Stream stream, ImageCropOpts cropOpts)
        {
            var meta = SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(obj);

            if (meta.VerifiedDetails > 1 && !currentUser.IsInRole("ModAdmin,ModSenior"))
            {
                throw new AccessViolationException("SaveLocationIndoorLogoImage: Only Senior Moderators can change images that have already been verified by other users");
            }

            return(meta);
        }
        /// <summary>
        /// Save the logo for an indoor climbing gym
        /// </summary>
        public string SaveLocationIndoorLogo(LocationIndoor obj, Stream stream, ImageCropOpts cropOpts)
        {
            var meta     = SaveLocationIndoorLogoAuthorization(obj, stream, cropOpts);
            var original = obj.GetSimpleTypeClone();

            var newImgUrl = SaveAvatar240Thumb(stream, obj.Logo, obj.NameUrlPart, ImageManager.LogoIndoorPath,
                                               fileName => { obj.Logo = fileName; locIndoorRepo.Update(obj); }, cropOpts);

            //-- No change occurs to the mods profile because the image has to be verified by other users
            SaveModActionAndUpdateModProfile(ModActionType.LocationIndoorSetLogo, original, obj, meta,
                                             null, // don't really have an action FK on the objModMeta just for the logo, so don't update it
                                             null, "set indoor logo {0}", obj.Name);

            //-- If we don't yet have an avatar/climbing image, let's use the logo for the avatar/map scroll over image
            //if (String.IsNullOrWhiteSpace(obj.ImageFileMap)) { SaveLocationIndoorAvatar(obj,  stream, cropOpts); }

            return(newImgUrl);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="original"></param>
        /// <param name="updated"></param>
        /// <returns></returns>
        public LocationIndoor UpdateLocationIndoor(LocationIndoor original, LocationIndoor updated)
        {
            var placeMeta = UpdateLocationIndoorAuthorization(original, updated);

            if (!original.Equals(updated))
            {
                locIndoorRepo.Update(updated);

                AppLookups.UpdateIndexEntryInCache(updated.ToCacheIndexEntry());

                var action = SaveModActionAndUpdateModProfile(ModActionType.LocationIndoorEdit, original, updated, placeMeta,
                                                              (m, actionID) => m.SetDetailsChanged(actionID), null, "edited {0} {1}", updated.Type, updated.Name);

                postSvc.UpdateContentAddPost(action);
            }

            return(updated);
        }
        ObjectModMeta DeleteLocationIndoorAuthorization(LocationIndoor obj)
        {
            var meta = SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(obj);

            if (meta.CQR > 7 && !currentUser.IsInRole("ModAdmin"))
            {
                throw new AccessViolationException("DeleteLocationIndoor: Only Admin Moderators can delete places with CQR higher than 7");
            }
            else if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
            {
                throw new AccessViolationException("DeleteLocationIndoor: Only Senior Moderators can delete places with CQR higher than 1");
            }
            else if (!currentUser.IsInRole("ModAdmin,ModSenior,ModCommunity"))
            {
                throw new AccessViolationException("DeleteLocationIndoor: You must be Moderator to delete places");
            }

            return(meta);
        }
Exemplo n.º 10
0
        public LocationIndoor CreateLocationIndoor(LocationIndoor ot)
        {
            using (SqlCommand cmd = new SqlCommand("geo.InsertLocationIndoor"))
            {
                AddLocationBaseParamters(cmd, ot, false);
                cmd.Parameters.Add("@Avatar", SqlDbType.NVarChar).Value = ot.Avatar.GetEmptyIfNull();
                cmd.Parameters.Add("@MapAddress", SqlDbType.NVarChar).Value = ot.MapAddress;
                cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = ot.Address;
                cmd.Parameters.Add("@Website", SqlDbType.NVarChar).Value = ot.Website;
                cmd.Parameters.Add("@IsPrivate", SqlDbType.Bit).Value = ot.IsPrivate;
                cmd.Parameters.Add("@Latitude", SqlDbType.Float).Value = ot.Latitude;
                cmd.Parameters.Add("@Longitude", SqlDbType.Float).Value = ot.Longitude;
                
                var newIDFromDB = ExecuteInsert(cmd);
                ot.ID = new Guid(newIDFromDB);
            }

            return ot;
        }
        ObjectModMeta DeleteLocationIndoorAuthorization(LocationIndoor obj)
        {
            var meta = SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(obj);

            if (meta.CQR > 7 && !currentUser.IsInRole("ModAdmin"))
            {
                throw new AccessViolationException("DeleteLocationIndoor: Only Admin Moderators can delete places with CQR higher than 7");
            }
            else if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
            {
                throw new AccessViolationException("DeleteLocationIndoor: Only Senior Moderators can delete places with CQR higher than 1");
            }
            else if (!currentUser.IsInRole("ModAdmin,ModSenior,ModCommunity"))
            {
                throw new AccessViolationException("DeleteLocationIndoor: You must be Moderator to delete places");
            }

            return meta;
        }
Exemplo n.º 12
0
 public void AddSetterToLocationIndoor(LocationIndoor loc, Setter setter)
 {
     locIndoorRepo.AddSetter(loc.ID, setter.ID);
 }
 /// <summary>
 /// No fancy authorization logic, just create the mod profile it it's the users first time & check they're not a bad egg (negative rep)
 /// </summary>
 void CreateLocationIndoorAuthorization(LocationIndoor obj)
 {
     SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(obj);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="original"></param>
        /// <param name="updated"></param>
        /// <returns></returns>
        public LocationIndoor UpdateLocationIndoor(LocationIndoor original, LocationIndoor updated)
        {
            var placeMeta = UpdateLocationIndoorAuthorization(original, updated);

            if (!original.Equals(updated))
            {
                locIndoorRepo.Update(updated);

                AppLookups.UpdateIndexEntryInCache(updated.ToCacheIndexEntry());

                var action = SaveModActionAndUpdateModProfile(ModActionType.LocationIndoorEdit, original, updated, placeMeta,
                    (m, actionID) => m.SetDetailsChanged(actionID), null, "edited {0} {1}", updated.Type, updated.Name);

                postSvc.UpdateContentAddPost(action);
            }

            return updated;
        }
        /// <summary>
        /// Save the logo for an indoor climbing gym
        /// </summary>
        public string SaveLocationIndoorLogo(LocationIndoor obj, Stream stream, ImageCropOpts cropOpts)
        {
            var meta = SaveLocationIndoorLogoAuthorization(obj, stream, cropOpts);
            var original = obj.GetSimpleTypeClone();

            var newImgUrl = SaveAvatar240Thumb(stream, obj.Logo, obj.NameUrlPart, ImageManager.LogoIndoorPath,
                fileName => { obj.Logo = fileName; locIndoorRepo.Update(obj); }, cropOpts);

            //-- No change occurs to the mods profile because the image has to be verified by other users
            SaveModActionAndUpdateModProfile(ModActionType.LocationIndoorSetLogo, original, obj, meta,
                    null, // don't really have an action FK on the objModMeta just for the logo, so don't update it
                    null, "set indoor logo {0}", obj.Name);

            //-- If we don't yet have an avatar/climbing image, let's use the logo for the avatar/map scroll over image
            //if (String.IsNullOrWhiteSpace(obj.ImageFileMap)) { SaveLocationIndoorAvatar(obj,  stream, cropOpts); }

            return newImgUrl;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        public void DeleteLocationIndoor(LocationIndoor obj)
        {
            var meta = DeleteLocationIndoorAuthorization(obj);

            locIndoorRepo.Delete(obj.ID);

            //-- Update the cache
            AppLookups.RemoveCacheIndexEntry(obj.ID);

            var modWhoAddedArea = modProfileRepo.GetByID(meta.CreatedByUserID);
            if (modWhoAddedArea.PlacesAdded > 0)
            {
                modWhoAddedArea.PlacesAdded--;
                modProfileRepo.Update(modWhoAddedArea);

                //-- Remove the points associated with this place
                var actionsWithPoints = modActionRepo.GetAll().Where(a => a.OnObjectID == meta.ID);
                ReverseActions(actionsWithPoints);
            }

            //-- update the principal details with the details we just updated (if they are the same person who deleted it)
            CfPrincipal.AttachModProfile(modProfileRepo.GetByID(currentUser.UserID));

            //-- Incase the name changed during the life of the object, we want to save the meta with the same name as the object was when it was deleted.
            meta.Name = obj.VerboseDisplayName;

            var action = SaveModActionAndUpdateModProfile(ModActionType.LocationIndoorDelete, obj, null, meta,
                     (m, actionID) => m.SetDeleted(actionID), null, "deleted {0} {1}", obj.Type, obj.Name);

            postSvc.DeleteContentAddPost(action);
        }
        ObjectModMeta SaveLocationIndoorLogoAuthorization(LocationIndoor obj, Stream stream, ImageCropOpts cropOpts)
        {
            var meta = SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(obj);

            if (meta.VerifiedDetails > 1 && !currentUser.IsInRole("ModAdmin,ModSenior"))
            {
                throw new AccessViolationException("SaveLocationIndoorLogoImage: Only Senior Moderators can change images that have already been verified by other users");
            }

            return meta;
        }
Exemplo n.º 18
0
 public void RemoveSetterFromLocationIndoor(LocationIndoor loc, Setter setter)
 {
     locIndoorRepo.RemoveSetter(loc.ID, setter.ID);
 }
Exemplo n.º 19
0
 public IQueryable <ClimbIndoor> GetCurrentClimbsOfIndoorLocation(LocationIndoor loc)
 {
     return(climbRepo.GetIndoorClimbsOfLocation(loc.ID).Where(c =>
                                                              (!c.SetDate.HasValue || c.SetDate < DateTime.Now) &&
                                                              (!c.DiscontinuedDate.HasValue || (c.DiscontinuedDate.Value > DateTime.Now))));
 }
Exemplo n.º 20
0
 public IQueryable <ClimbIndoor> GetClimbsIndoorOfLocation(LocationIndoor loc)
 {
     return(climbRepo.GetIndoorClimbsOfLocation(loc.ID));
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="original"></param>
        /// <param name="updated"></param>
        /// <returns></returns>
        ObjectModMeta UpdateLocationIndoorAuthorization(LocationIndoor original, LocationIndoor updated)
        {
            var meta = SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(original);

            if (original.ID != updated.ID || original.CountryID != updated.CountryID)
            {
                throw new ArgumentException(string.Format("Original indoor location {0}[{1}][{2}] is not the same as updated {3}[{4}][{5}]",
                    original.Name, original.CountryID, original.ID, updated.Name, updated.CountryID, updated.ID));
            }

            if ((original.Latitude != updated.Latitude) || (original.Longitude != updated.Longitude))
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the position of a verified outdoor location.");
                }
            }

            if ((original.Name != updated.Name))
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the name of an outdoor location that has already been verified.");
                }
            }

            if ((original.NameUrlPart != updated.NameUrlPart))
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the url.");
                }
            }

            if ((original.Description != updated.Description) && meta.CQR > 6)
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the description of an outdoor location that has been verified and has a high CQR.");
                }
            }

            if (original.Address != updated.Address)
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the address.");
                }
            }

            if (original.Website != updated.Website)
            {
                if (meta.HasBeenVerified && !currentUser.IsInRole("ModAdmin,ModSenior"))
                {
                    throw new AccessViolationException("UpdateLocationIndoor[" + original.ID + "]: Only Senior Moderators can change the website.");
                }
            }

            return meta;
        }
 private void SetLocationIndoorEditViewData(LocationIndoor location)
 {
     ViewBag.Location = location;
     ViewBag.LogoImageToDisplayUrl = (location.HasLogo) ? Stgs.ImgsRt + location.LogoRelativeUrl : Stgs.DefaultMapInfoImage;
     var climbImageToDisplay = (location.HasAvatar) ? Stgs.ImgsRt + location.AvatarRelativeUrl : Stgs.DefaultMapInfoImage;
     ViewBag.ClimbingImageToDisplayUrl = climbImageToDisplay;
 }
 /// <summary>
 /// No fancy authorization logic, just create the mod profile it it's the users first time & check they're not a bad egg (negative rep)
 /// </summary>
 void CreateLocationIndoorAuthorization(LocationIndoor obj)
 {
     SetModDetailsOnPrincipalAndStopModIfNegativeReputationAndReturnObjectModMeta(obj);
 }