/// <summary> /// Save the image used to represent the climb in thumbnails and on the main page. Also saves the image to the climbs media stream /// </summary> /// <param name="obj"></param> /// <param name="stream"></param> /// <param name="cropOptions"></param> /// <returns></returns> public Media SaveClimbAvatar(Climb obj, Stream stream, ImageCropOpts cropOptions) { ObjectModMeta meta = null; //-- We don't need to set ModProfile on thread, or retrieve object mod-meta for indoor climbs if (obj.Type == CfType.ClimbOutdoor) { meta = SaveClimbAvatarAuthorization(obj, stream, cropOptions); } var original = obj.GetSimpleTypeClimbClone(); //-- Also save the image to the climbs's media real //-- If the climb is indoor we don't save indoor climb avatar as var media = new MediaService().CreateImageMedia(new Media() { FeedVisible = (obj.Type != CfType.ClimbIndoor), Title = "Climbing pic of " + obj.Name, ContentType = "image/jpg" }, obj.ID, stream); SaveAvatar240Thumb(stream, obj.Avatar, obj.NameUrlPart, ImageManager.ClimbPath, fileName => { obj.Avatar = fileName; climbRepo.Update(obj); }, cropOptions, media.Content); //-- We don't want to save mod trail if it's indoor (the setters working, kinda boring!) if (obj.Type == CfType.ClimbOutdoor) { //-- No change occurs to the mods profile because the image has to be verified by other users SaveModActionAndUpdateModProfile(ModActionType.ClimbSetAvatar, original, obj, meta, (m, actionID) => m.SetAvatarChanged(actionID), null, "set climb img {0}", obj.Name); } return(media); }
/// <summary> /// /// </summary> /// <param name="place"></param> /// <returns></returns> public ObjectModMeta GetObjectModMetaOrSystemCreate(ISearchable place) { var modMeta = objModMetaRepo.GetByID(new Guid(place.IDstring)); if (modMeta == default(ObjectModMeta)) { modMeta = new ObjectModMeta(place, Stgs.SystemID); objModMetaRepo.Create(modMeta); } return(modMeta); }
/// <summary> /// Record the action taken by a moderator by setting the action on the object which it is related to, updates the moderators profiles (adds points) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="type"></param> /// <param name="original"></param> /// <param name="updated"></param> /// <param name="modMeta"></param> /// <param name="modMetaUpdateAction"></param> /// <param name="modProfileUpdateAction"></param> /// <param name="descriptionFormat"></param> /// <param name="descriptionArgs"></param> internal ModAction SaveModActionAndUpdateModProfile <T>(ModActionType type, T original, T updated, ObjectModMeta modMeta, Action <ObjectModMeta, Guid> modMetaUpdateAction, Action <ModProfile> modProfileUpdateAction, string descriptionFormat, params object[] descriptionArgs) where T : IOOObject, new () { ModAction action; //-- Generate a unique ID for the action var newActionID = Guid.NewGuid(); //-- Look up the points associated with the action byte reputationPointsForAction = type.GetPoints(); //-- Description (Used for the mod action feed) string actionDescription = currentUser.FullName + " " + string.Format(descriptionFormat, descriptionArgs); //-- TODO wrap this in a transaction/single data hit { //-- Step 1 save the mod action action = modActionRepo.Create(new ModAction() { ID = newActionID, TypeID = (int)type, OnObjectID = modMeta.ID, Description = actionDescription, Data = original.DifferenceAsJson(updated, original.GetCompareIgnorePropertyNames()), UserID = currentUser.UserID, Utc = DateTime.UtcNow, Points = reputationPointsForAction, Comment = string.Empty }); //-- Step 2 update the objModMeta Action Foreign Key & update the object if (modMetaUpdateAction != null) { modMetaUpdateAction(modMeta, newActionID); } objModMetaRepo.Update(modMeta); //-- Step 3 is update the moderators profile if (modProfileUpdateAction != null) { modProfileUpdateAction(CfPrincipal.ModDetails); } CfPrincipal.ModDetails.LastActivityUtc = DateTime.UtcNow; CfPrincipal.ModDetails.Reputation += reputationPointsForAction; modProfileRepo.Update(CfPrincipal.ModDetails); } return(action); }
public PlaceWithModDetails(CfCacheIndexEntry place, ObjectModMeta modDetails) { _place = place; _modDetails = modDetails; }