Пример #1
0
        public async Task <IActionResult> Update(int?advisorId, int?reportingPeriodId, string value)
        {
            if (reportingPeriodId == null)
            {
                return(NotFound());
            }
            if (advisorId == null)
            {
                return(NotFound());
            }
            if (decimal.TryParse(value, out decimal budget))
            {
                MLFSReportingPeriod period = await _periodData.GetPeriodById((int)reportingPeriodId);

                if (period == null)
                {
                    return(NotFound());
                }
                List <MLFSBudget> budgets = await _budgetData.GetBudgets(period);

                MLFSBudget b = budgets.Where(x => x.AdvisorId == advisorId).FirstOrDefault();
                if (b == null)
                {
                    b = new MLFSBudget()
                    {
                        AdvisorId         = (int)advisorId,
                        Budget            = budget,
                        ReportingPeriodId = period.Id
                    };
                    _budgetData.Insert(b);
                }
                else
                {
                    b.Budget = budget;
                    _budgetData.Update(b);
                }
                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }