private async Task <Follows.Models.Follow> FollowCreated(Follows.Models.Follow follow) { if (follow == null) { return(null); } // Is this a label follow? if (!follow.Name.Equals(FollowTypes.Label.Name, StringComparison.OrdinalIgnoreCase)) { return(follow); } // Get the label we are following var label = await _labelStore.GetByIdAsync(follow.ThingId); if (label == null) { return(follow); } // Update follow count label.TotalFollows = label.TotalFollows + 1; // Persist changes var updatedLabel = await _labelStore.UpdateAsync(label); if (updatedLabel != null) { // Award reputation for following label await _reputationAwarder.AwardAsync(Reputations.NewFollow, follow.CreatedUserId, $"Followed label \"{label.Name}\""); } return(follow); }
public async Task <ICommandResult <TLabel> > UpdateAsync(TLabel model) { // Validate if (model == null) { throw new ArgumentNullException(nameof(model)); } if (model.FeatureId <= 0) { throw new ArgumentNullException(nameof(model.FeatureId)); } if (model.Id <= 0) { throw new ArgumentOutOfRangeException(nameof(model.Id)); } if (String.IsNullOrWhiteSpace(model.Name)) { throw new ArgumentNullException(nameof(model.Name)); } if (model.CreatedUserId <= 0) { throw new ArgumentOutOfRangeException(nameof(model.CreatedUserId)); } if (model.CreatedDate == null) { throw new ArgumentNullException(nameof(model.CreatedDate)); } // Configure model model.Alias = await ParseAlias(model.Name); // Invoke LabelUpdating subscriptions foreach (var handler in _broker.Pub <TLabel>(this, "LabelUpdating")) { model = await handler.Invoke(new Message <TLabel>(model, this)); } var result = new CommandResult <TLabel>(); var label = await _labelStore.UpdateAsync(model); if (label != null) { // Invoke LabelUpdated subscriptions foreach (var handler in _broker.Pub <TLabel>(this, "LabelUpdated")) { label = await handler.Invoke(new Message <TLabel>(label, this)); } // Return success return(result.Success(label)); } return(result.Failed(new CommandError("An unknown error occurred whilst attempting to update the Label"))); }