示例#1
0
        public static Collective CreateAndAdd(ApplicationDbContext context, string Name, string CreatorUserId, string ShareName, string ShareIdentifier, int?TotalShares, bool IsTransferable, bool AssetBacked, int?UserShares, int UserVoteClout, Guid?id = null)
        {
            var collective = context.Collectives.Create();

            if (id == null)
            {
                id = Guid.NewGuid();
            }

            var user = context.Users.Find(new object[] { CreatorUserId });

            collective.Id            = (Guid)id;
            collective.TimeStamp     = DateTime.UtcNow;
            collective.CreatorUserId = CreatorUserId;

            var cm = new CollectiveMember {
                Id = Guid.NewGuid(), CollectiveId = collective.Id, UserId = CreatorUserId, TimeStamp = DateTime.UtcNow
            };
            var l = new Ledger {
                Id = Guid.NewGuid(), CollectiveId = collective.Id, Name = "System", Description = "Ledger used for all core system actions", TimeStamp = DateTime.UtcNow
            };

            context.Collectives.Add(collective);
            context.CollectiveMembers.Add(cm);
            context.Ledgers.Add(l);

            var Actions = LedgerEntry.CreateAndAdd(context, l, null, LEDGER_ACTION_TYPE.General, "Initialize " + Name + " Collective")
                          .SetStatus(ACTION_STATUS.Open);

            LedgerEntry.CreateAndAddToGroup(context, Actions, null, LEDGER_ACTION_TYPE.CreateCollective, "Create Collective");

            LedgerEntry.CreateAndAddToGroup(context, Actions, null, LEDGER_ACTION_TYPE.SetCollectiveName, "Set Collective Name")
            .SetParm("NewName", Name);

            LedgerEntry.CreateAndAddToGroup(context, Actions, null, LEDGER_ACTION_TYPE.AddMember, "Create User " + Name + ": " + user.UserName + " (" + user.Email + ")")
            .SetParm("Username", user.UserName);

            LedgerEntry.CreateAndAddToGroup(context, Actions, null, LEDGER_ACTION_TYPE.SetPermission, "Set permission for " + user.NameFull)
            .SetParm("AssignTo", Guid.Parse(user.Id))
            .SetParm("Action", LEDGER_ACTION_TAG.All)
            .SetParm("Propose", true)
            .SetParm("ExecuteWithoutVote", true)
            .SetParm("AssignToOthers", true);

            LedgerEntry.CreateAndAddToGroup(context, Actions, null, LEDGER_ACTION_TYPE.IncreaseVoteClout, "Increase Vote Clout for " + user.NameFull)
            .SetParm("User", user.Id)
            .SetParm("Ledger", l.Id)
            .SetParm("NewVoteClout", 1);

            if (ShareName != null)
            {
                var ShareTypeLedgerId = LedgerEntry.CreateAndAddToGroup(context, Actions, CreatorUserId, LEDGER_ACTION_TYPE.CreateShareType, "Create Share Type " + ShareIdentifier + ": " + ShareName)
                                        .SetFlags(LEDGER_ACTION_FLAG.Privileged)
                                        .SetParm("Name", ShareName)
                                        .SetParm("Identifier", ShareIdentifier)
                                        .SetParm("IsTransferable", IsTransferable)
                                        .SetParm("AssetBacked", AssetBacked)
                                        .Id;

                if (TotalShares != null)
                {
                    LedgerEntry.CreateAndAddToGroup(context, Actions, CreatorUserId, LEDGER_ACTION_TYPE.SetShareQuantity, "Set Share Quantity of " + ShareIdentifier + " to " + TotalShares.ToString())
                    .SetFlags(LEDGER_ACTION_FLAG.Privileged)
                    .SetParmFromResults <Guid>("ShareType", ShareTypeLedgerId, 1)
                    .SetParm("NewTotalShares", TotalShares);
                }

                if (UserShares != null)
                {
                    LedgerEntry.CreateAndAddToGroup(context, Actions, CreatorUserId, LEDGER_ACTION_TYPE.IncreaseShares, "Increase " + ShareIdentifier + " Shares for " + user.UserName)
                    .SetFlags(LEDGER_ACTION_FLAG.Privileged)
                    .SetParm("User", user.Id)
                    .SetParmFromResults <Guid>("ShareType", ShareTypeLedgerId, 1)
                    .SetParm("NewNumberOfShares", (int)UserShares);
                }
            }

            Actions.Execute((int)LEDGER_ACTION_FLAG.SystemAutomatic);

            return(collective);
        }
示例#2
0
文件: Ledger.cs 项目: cogov/CoGov.NET
 public LedgerEntry Entry(LedgerEntry LE)
 {
     LE.LedgerId = this.Id;
     return(LE);
 }