public IActionResult Put([FromBody] Budget budget) { var userFromAuth = UserService.GetUserFromClaims(this.User, UserRepo, RequestLogger); RequestLogger.UserId = userFromAuth.Id.ToString(); var accounts = AccountRepo.FindAllByOwner(userFromAuth.Id); CompleteMissingAccountActuals(budget, userFromAuth.Id, accounts); BudgetRepo.Upsert(budget, userFromAuth.UserName); var savedBudget = BudgetRepo.FindById(userFromAuth.Id, budget.Id); savedBudget.UpgradeBudgetIfNeeded(AccountRepo.FindAllByOwner(userFromAuth.Id)); return(Ok(savedBudget)); }
public IActionResult Post([FromBody] BudgetCopyRequest budgetCopyRequest) { var userFromAuth = UserService.GetUserFromClaims(this.User, UserRepo, RequestLogger); RequestLogger.UserId = userFromAuth.Id.ToString(); if (budgetCopyRequest.SourceId.CompareTo(Guid.Empty) == 0) { return(StatusCode(400, "Invalid Source ID.")); } if (budgetCopyRequest.DestinationMonth <= 0 || budgetCopyRequest.DestinationMonth > 12 || budgetCopyRequest.DestinationYear < 2000) { return(StatusCode(400, "Invalid Destination Month or Year.")); } if (budgetCopyRequest.DestinationDescription.IsNullOrEmpty()) { return(StatusCode(400, "Invalid Destination Description.")); } var sourceBudget = BudgetRepo.FindById(userFromAuth.Id, budgetCopyRequest.SourceId); // Not found, create a new "blank" budget they can use instead. if (sourceBudget == null) { return(NotFound($"Budget Source with ID '{budgetCopyRequest.SourceId}' Not Found.")); } var destinationBudget = BudgetService.BuildNewBudget(budgetCopyRequest.DestinationDescription, budgetCopyRequest.DestinationYear, budgetCopyRequest.DestinationMonth, userFromAuth.Id, userFromAuth.UserName); destinationBudget.UpgradeBudgetIfNeeded(AccountRepo.FindAllByOwner(userFromAuth.Id)); sourceBudget.CopyFinancialsToDestinationBudget(destinationBudget, budgetCopyRequest.CopyActuals, true); BudgetRepo.Upsert(destinationBudget, userFromAuth.UserName); var savedBudget = BudgetRepo.FindById(userFromAuth.Id, destinationBudget.Id); return(Ok(savedBudget)); }