using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Runtime.Serialization; using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; namespace Umbraco.Web.Models.ContentEditing { [DataContract(Name = "userGroup", Namespace = "")] public class UserGroupSave : EntityBasic, IValidatableObject { /// /// The action to perform when saving this user group /// /// /// If either of the Publish actions are specified an exception will be thrown. /// [DataMember(Name = "action", IsRequired = true)] [Required] public ContentSaveAction Action { get; set; } [DataMember(Name = "alias", IsRequired = true)] [Required] public override string Alias { get; set; } [DataMember(Name = "sections")] public IEnumerable Sections { get; set; } [DataMember(Name = "users")] public IEnumerable Users { get; set; } [DataMember(Name = "startContentId")] public int? StartContentId { get; set; } [DataMember(Name = "startMediaId")] public int? StartMediaId { get; set; } /// /// The list of letters (permission codes) to assign as the default for the user group /// [DataMember(Name = "defaultPermissions")] public IEnumerable DefaultPermissions { get; set; } /// /// The assigned permissions for content /// /// /// The key is the content id and the list is the list of letters (permission codes) to assign /// [DataMember(Name = "assignedPermissions")] public IDictionary> AssignedPermissions { get; set; } /// /// The real persisted user group /// [IgnoreDataMember] internal IUserGroup PersistedUserGroup { get; set; } public IEnumerable Validate(ValidationContext validationContext) { if (DefaultPermissions.Any(x => x.IsNullOrWhiteSpace())) { yield return new ValidationResult("A permission value cannot be null or empty", new[] { "Permissions" }); } foreach (var assignedPermission in AssignedPermissions) { foreach (var permission in assignedPermission.Value) { if (permission.IsNullOrWhiteSpace()) yield return new ValidationResult("A permission value cannot be null or empty", new[] { "AssignedPermissions" }); } } } } }