Example #1
0
        /// <summary>
        /// Tos the entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="context">Context.</param>
        /// <param name="input">Input.</param>
        public ThematicCommunity ToEntity(IfyContext context, ThematicCommunity input)
        {
            ThematicCommunity entity = (input == null ? new ThematicCommunity(context) : input);

            entity.DiscussCategory   = DiscussCategory;
            entity.AppsLinks         = Apps;
            entity.IconUrl           = IconeUrl;
            entity.Identifier        = TepUtility.ValidateIdentifier(Identifier);
            entity.Name              = Name;
            entity.Description       = Description;
            entity.EmailNotification = EmailNotification;
            entity.EnableJoinRequest = EnableJoinRequest;
            entity.DefaultRoleName   = DefaultRole;
            entity.Contributor       = Contributor;
            entity.ContributorIcon   = ContributorIcon;
            if (Kind == (int)DomainKind.Public || Kind == (int)DomainKind.Private || Kind == (int)DomainKind.Hidden)
            {
                entity.Kind = (DomainKind)Kind;
            }
            entity.Links = new List <RemoteResource>();
            if (Links != null && Links.Count > 0)
            {
                foreach (WebDataPackageItem item in Links)
                {
                    RemoteResource res = (item.Id == 0) ? new RemoteResource(context) : RemoteResource.FromId(context, item.Id);
                    res = item.ToEntity(context, res);
                    entity.Links.Add(res);
                }
            }
            return(entity);
        }
Example #2
0
        /// <summary>
        /// Writes the item to the database.
        /// </summary>
        public override void Store()
        {
            context.StartTransaction();
            if (DomainId == 0 && Owner != null)
            {
                DomainId = Owner.Domain.Id;
            }
            if (DomainId == -1)
            {
                DomainId = 0;
            }
            bool isNew = this.Id == 0;

            try {
                if (isNew)
                {
                    this.AccessKey    = Guid.NewGuid().ToString();
                    this.CreationTime = DateTime.UtcNow;
                    if (string.IsNullOrEmpty(this.Identifier))
                    {
                        this.Identifier = GetUniqueIdentifier(this.Name);
                    }
                    else
                    {
                        this.Identifier = TepUtility.ValidateIdentifier(this.Identifier);
                    }
                }
                base.Store();

                if (isNew && context.AccessLevel == EntityAccessLevel.Administrator)
                {
                    var count = context.GetQueryIntegerValue(String.Format("SELECT count(*) FROM {3} WHERE id_{2}={0} AND id_usr={1};", Id, OwnerId, this.EntityType.PermissionSubjectTable.Name, this.EntityType.PermissionSubjectTable.PermissionTable));
                    if (count == 0)
                    {
                        context.Execute(String.Format("INSERT INTO {3} (id_{2}, id_usr) VALUES ({0}, {1});", Id, OwnerId, this.EntityType.PermissionSubjectTable.Name, this.EntityType.PermissionSubjectTable.PermissionTable));
                    }
                }

                if (Kind == KINDRESOURCESETUSER)
                {
                    this.GrantPermissionsToUsers(new int [] { Owner.Id }, true);
                }

                Resources.StoreExactly();
                LoadItems();
                context.Commit();
            } catch (Exception e) {
                context.Rollback();
                throw e;
            }
        }
Example #3
0
        /// <summary>
        /// Gets the unique identifier.
        /// </summary>
        /// <returns>The unique identifier.</returns>
        /// <param name="name">Name.</param>
        public string GetUniqueIdentifier(string name)
        {
            var identifier = string.IsNullOrEmpty(name) ? this.Identifier : TepUtility.ValidateIdentifier(name);

            try {
                DataPackage.FromIdentifier(context, identifier);
            } catch (EntityUnauthorizedException) {
                //next
            } catch (EntityNotFoundException) {
                return(identifier);
            }
            for (int i = 0; i < 1000; i++)
            {
                var uname = string.Format("{0}{1}", identifier, i == 0 ? "" : "-" + i);
                try{
                    DataPackage.FromIdentifier(context, uname);
                } catch (EntityUnauthorizedException) {
                    //next
                }catch (EntityNotFoundException) {
                    return(uname);
                }
            }
            throw new Exception("Sorry, we were not able to find a valid data package name");
        }