Example #1
0
        public async Task <IActionResult> Post([FromBody] Group userInputGroup)
        {
            // requestor is a group administration and can create groups
            if (!(await _securityHelper.IsGroupAdmin()))
            {
                return(new HttpStatusCodeResult(403)); // Forbidden;
            }
            //TODO: group parameter validation

            // get current user
            var currentUser = await _securityHelper.GetOrCreateCurrentUser();

            // build the resource group object
            var group = new ScampResourceGroup()
            {
                Id          = Guid.NewGuid().ToString(),
                Name        = userInputGroup.Name,
                Description = userInputGroup.Description,
                Budget      = new ScampGroupBudget()
                {
                    OwnerId               = currentUser.Id,
                    OwnerName             = currentUser.Name,
                    unitsBudgeted         = userInputGroup.Budget.unitsBudgeted,
                    DefaultUserAllocation = userInputGroup.Budget.defaultUserBudget,
                    EndDate               = userInputGroup.Budget.expiryDate
                }
            };

            await _groupRepository.CreateGroup(group);

            // after we know the user docs have completed successfully, add the volatile storage records
            Task[] tasks = new Task[2]; // collection to hold the parallel tasks

            // create group volatile storage entries
            var newGrpBudget = new GroupBudgetState(group.Id)
            {
                UnitsBudgetted = userInputGroup.Budget.unitsBudgeted,
                UnitsAllocated = userInputGroup.Budget.defaultUserBudget,
                UnitsUsed      = 0
            };

            tasks[0] = _volatileStorageController.AddGroupBudgetState(newGrpBudget);

            // create volatile storage budget entry for user/group
            var newUsrBudget = new UserBudgetState(currentUser.Id, group.Id)
            {
                UnitsBudgetted = group.Budget.DefaultUserAllocation,
                UnitsUsed      = 0
            };

            tasks[1] = _volatileStorageController.AddUserBudgetState(newUsrBudget);

            // wait for both operations to complete
            Task.WaitAll(tasks);

            return(new ObjectResult(Map(group))
            {
                StatusCode = 200
            });
        }
 public async Task AddGroupBudgetState(GroupBudgetState budget)
 {
     TableOperation operation = TableOperation.InsertOrReplace(budget);
     TableResult retrievedResult = await _StateUpdateTable.ExecuteAsync(operation);
     return;
 }
Example #3
0
        public async Task<IActionResult> Post([FromBody]Group userInputGroup)
        {
            // requestor is a group administration and can create groups
            if (!(await _securityHelper.IsGroupAdmin()))
                return new HttpStatusCodeResult(403); // Forbidden;

            //TODO: group parameter validation 

            // get current user
            var currentUser = await _securityHelper.GetOrCreateCurrentUser();

            // build the resource group object
            var group = new ScampResourceGroup()
            {
                Id = Guid.NewGuid().ToString(),
                Name = userInputGroup.Name,
                Description = userInputGroup.Description,
                Budget = new ScampGroupBudget()
                {
                    OwnerId = currentUser.Id,
                    OwnerName = currentUser.Name,
                    unitsBudgeted = userInputGroup.Budget.unitsBudgeted,
                    DefaultUserAllocation = userInputGroup.Budget.defaultUserBudget,
                    EndDate = userInputGroup.Budget.expiryDate
                }
            };

            await _groupRepository.CreateGroup(group);

            // after we know the user docs have completed successfully, add the volatile storage records
            Task[] tasks = new Task[2]; // collection to hold the parallel tasks
            
            // create group volatile storage entries
            var newGrpBudget = new GroupBudgetState(group.Id)
            {
                UnitsBudgetted = userInputGroup.Budget.unitsBudgeted,
                UnitsAllocated = userInputGroup.Budget.defaultUserBudget,
                UnitsUsed = 0
            };
            tasks[0] = _volatileStorageController.AddGroupBudgetState(newGrpBudget);

            // create volatile storage budget entry for user/group
            var newUsrBudget = new UserBudgetState(currentUser.Id, group.Id)
            {
                UnitsBudgetted = group.Budget.DefaultUserAllocation,
                UnitsUsed = 0
            };
            tasks[1] = _volatileStorageController.AddUserBudgetState(newUsrBudget);

            // wait for both operations to complete
            Task.WaitAll(tasks);

            return new ObjectResult(Map(group)) { StatusCode = 200 };
        }