Exemple #1
0
        public async Task <IActionResult> Update([FromHeader] string authToken, string id, BudgetRequestUpdate budgetRequestUpdate)
        {
            if (!await _authenticationService.CheckAccess(authToken, "budgetMgr"))
            {
                return(Unauthorized());
            }

            var budgetRequest = await _budgetRequestService.Get(id);

            if (budgetRequest == null)
            {
                return(NotFound());
            }

            _budgetRequestService.Update(budgetRequest, budgetRequestUpdate);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document modified.",
                                         "budgetRequests",
                                         id,
                                         JsonSerializer.Serialize(BudgetRequest.FromUpdate(budgetRequest, budgetRequestUpdate))
                                         ));

            if (budgetRequestUpdate.StockroomApprovedFlag)
            {
                LabGroup group = await _labGroupService.GetByMemberId(AuthenticationHelpers.GetUserIdFromToken(authToken));

                group.Budget        = group.Budget + budgetRequestUpdate.IncreaseAmount;
                group.BudgetBalance = group.BudgetBalance + budgetRequestUpdate.IncreaseAmount;

                group.Transactions.Add(new Transaction(
                                           null,
                                           "Add",
                                           "Budget Increase",
                                           budgetRequestUpdate.IncreaseAmount,
                                           DateTime.UtcNow
                                           ));

                _labGroupService.Update(group, group.Id);

                await _logService.Create(new Log(
                                             null,
                                             AuthenticationHelpers.GetUserIdFromToken(authToken),
                                             DateTime.UtcNow,
                                             "Document modified.",
                                             "budgetRequests",
                                             id,
                                             JsonSerializer.Serialize(group)
                                             ));

                if (!_hostEnvironment.EnvironmentName.Equals("Development", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (string userId in group.Members)
                    {
                        User temp = await _userService.Get(userId);

                        EmailHelpers.SendBudgetRequestApprovedEmail(temp.TechMail);
                    }
                }
            }

            return(Ok());
        }
Exemple #2
0
 public async void Update(BudgetRequest original, BudgetRequestUpdate update) =>
 await _budgetRequests.ReplaceOneAsync(budgetRequest => budgetRequest.Id == original.Id, BudgetRequest.FromUpdate(original, update));