/// <summary> /// /// </summary> /// <returns></returns> public UserReactionsTypes GetTypesTableWithStyles() { var reactionSettings = _orchardServices.WorkContext.CurrentSite.As <UserReactionsSettingsPart>(); var userRT = new UserReactionsTypes(); var styleAcronime = new Laser.Orchard.UserReactions.StyleAcroName(); userRT.CssName = reactionSettings.StyleFileNameProvider; userRT.AllowMultipleChoices = reactionSettings.AllowMultipleChoices; userRT.UserReactionsType = GetTypesTable().Select(r => new UserReactionsTypeVM { Id = r.Id, Priority = r.Priority, TypeName = r.TypeName, Activating = r.Activating, Delete = false }).ToList(); int newPriority = userRT.UserReactionsType.Count + 1; foreach (var type in Enum.GetNames(typeof(ReactionsNames))) { if (userRT.UserReactionsType.FirstOrDefault(x => x.TypeName == type) == null) { userRT.UserReactionsType.Add(new UserReactionsTypeVM { Id = 0, Activating = false, Delete = false, Priority = newPriority, TypeName = type }); newPriority++; } } return(userRT); }
public ActionResult Settings(UserReactionsTypes model) { if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Yout have to be an Administrator to edit Reaction types settings!"))) { return(new HttpUnauthorizedResult()); } if (!ModelState.IsValid) { _orchardServices.Notifier.Error(T("Settings update failed: {0}", T("check your input!"))); return(View(model)); } var reactionSettings = _orchardServices.WorkContext.CurrentSite.As <UserReactionsSettingsPart>(); reactionSettings.StyleFileNameProvider = model.CssName; reactionSettings.AllowMultipleChoices = model.AllowMultipleChoices; bool newTypesCreated = false; foreach (var item in model.UserReactionsType) { if (item.Id == 0) { var styleAcronime = new Laser.Orchard.UserReactions.StyleAcroName(); string styleAcronimeName = styleAcronime.StyleAcronime + item.TypeName; _repoTypes.Create(new Models.UserReactionsTypesRecord { Priority = item.Priority, TypeName = item.TypeName, Activating = item.Activating }); newTypesCreated = true; } else { var record = _repoTypes.Get(item.Id); record.Priority = item.Priority; record.TypeName = item.TypeName; record.Activating = item.Activating; _repoTypes.Update(record); } } if (newTypesCreated) { // allinea i contenuti tramite un task schedulato _taskManager.CreateTask("Laser.Orchard.UserReactionsSettings.Task", DateTime.UtcNow.AddSeconds(5), null); _notifier.Add(NotifyType.Warning, T("A task has been scheduled to update reaction summaries for existing contents.")); } _notifier.Add(NotifyType.Information, T("UserReaction settings updating")); return(RedirectToActionPermanent("Settings")); }