public ManageGroups() { InitializeComponent(); this.TopLevel = false; daoGroup = new DaoGroup(); ShowListRoles(this.gridRoles); }
public async Task <API.Response.GroupInfo> ToGroupInfo(long userId, DaoGroup daoGroup) { return(new API.Response.GroupInfo() { Id = daoGroup.Id, Name = daoGroup.Name, Creator = daoGroup.CreatorUser.DisplayName, MemberCount = daoGroup.Members.Count(), MyCurrentBalance = await _spendingService.GetDebtSum(userId, daoGroup.Id) }); }
public async Task <GroupInfo> ToGroupInfo(long userId, DaoGroup daoGroup) { return(new GroupInfo() { Id = daoGroup.Id, Name = daoGroup.Name, Creator = daoGroup.CreatorUser.DisplayName, MemberCount = daoGroup.Members.Count(), MyCurrentBalance = await GetDebtSum(userId, daoGroup.Id) }); }
public async Task LogCreateGroup(long userId, DaoGroup newGroup) { dynamic historyEntry = new ExpandoObject(); // Name historyEntry.Name = newGroup.Name; // Id historyEntry.Id = newGroup.Id; // Log await LogHistory(userId, newGroup.Id, new long[] { userId }, DaoLogType.Type.CREATE, DaoLogSubType.Type.GROUP, historyEntry); }
public async Task CreateGroup(long userId, NewGroup newGroup) { using (var transaction = Context.Database.BeginTransaction(System.Data.IsolationLevel.Serializable)) { try { var existingGroup = await Context.Groups .SingleOrDefaultAsync(x => x.CreatorUserId == userId && x.Name == newGroup.Name); if (existingGroup != null) { throw new BusinessException("name_taken"); } var daoGroup = new DaoGroup() { CreatorUserId = userId, Name = newGroup.Name }; await Context.Groups.AddAsync(daoGroup); if (await Context.SaveChangesAsync() != 1) { throw new DatabaseException("group_not_created"); } await History.LogCreateGroup(userId, daoGroup); if (await Context.SaveChangesAsync() != 1) { throw new DatabaseException("group_create_history_not_saved"); } transaction.Commit(); } catch { transaction.Rollback(); throw; } } }
public async Task <API.Response.GroupData> ToGroupData(long userId, DaoGroup daoGroup) { return(new API.Response.GroupData() { Id = daoGroup.Id, Name = daoGroup.Name, Creator = new API.Response.MemberData() { Id = daoGroup.CreatorUserId, Name = daoGroup.CreatorUser.DisplayName, Balance = await _spendingService.GetDebtSum(userId, daoGroup.Id) }, Members = daoGroup.Members.Select(async daoUsersGroupsMap => new API.Response.MemberData() { Id = daoUsersGroupsMap.UserId, Name = daoUsersGroupsMap.User.DisplayName, Balance = await _spendingService.GetDebtSum(daoUsersGroupsMap.UserId, daoGroup.Id) }).Select(x => x.Result).ToList(), MyCurrentBalance = await _spendingService.GetDebtSum(userId, daoGroup.Id) }); }
public async Task <GroupData> ToGroupData(long userId, DaoGroup daoGroup) { return(new GroupData() { Id = daoGroup.Id, Name = daoGroup.Name, Creator = new MemberData() { Id = daoGroup.CreatorUserId, Name = daoGroup.CreatorUser.DisplayName, Balance = await GetDebtSum(userId, daoGroup.Id), BankAccountNumber = daoGroup.CreatorUser.BankAccountNumber ?? "" }, Members = daoGroup.Members.Select(async daoUsersGroupsMap => new MemberData() { Id = daoUsersGroupsMap.UserId, Name = daoUsersGroupsMap.User.DisplayName, Balance = await GetDebtSum(daoUsersGroupsMap.UserId, daoGroup.Id), BankAccountNumber = daoUsersGroupsMap.User.BankAccountNumber ?? "" }).Select(x => x.Result).ToList(), MyCurrentBalance = await GetDebtSum(userId, daoGroup.Id) }); }