public ActionResult ExpensesModal(int id)
        {
            var timesheet = timesheetService.GetTimesheet(id);

            var mon = timesheet.WeekEnding.GetWeekStartDate();
            var tue = mon.AddDays(1);
            var wed = mon.AddDays(2);
            var thu = mon.AddDays(3);
            var fri = mon.AddDays(4);
            var sat = mon.AddDays(5);
            var sun = mon.AddDays(6);

            var expenses = expensesService.GetExpenses(timesheet.CarerID, null, null, null)
                           .Where(x => x.AgreementID == timesheet.AgreementID && x.ExpenseDate >= mon && x.ExpenseDate <= sun)
                           .ToList();

            foreach (var date in new DateTime[] { mon, tue, wed, thu, fri, sat, sun })
            {
                var dayExpenses = expenses.Where(x => x.ExpenseDate == date);
                {
                    if (!dayExpenses.Any(x => x.Type == ExpenseType.Mileage))
                    {
                        expenses.Add(new Expense()
                        {
                            CarerID = timesheet.CarerID, AgreementID = timesheet.AgreementID, Type = ExpenseType.Mileage, ExpenseDate = date
                        });
                    }
                    if (!dayExpenses.Any(x => x.Type == ExpenseType.Other))
                    {
                        expenses.Add(new Expense()
                        {
                            CarerID = timesheet.CarerID, AgreementID = timesheet.AgreementID, Type = ExpenseType.Other, ExpenseDate = date
                        });
                    }
                }
            }

            var canEdit = !(timesheet.CarerPaymentGenerated || timesheet.CustomerPaymentGenerated);

            ViewBag.CanEdit       = canEdit;
            ViewBag.WeekEnding    = timesheet.WeekEnding;
            ViewBag.Carer         = timesheet.Carer;
            ViewBag.CareRecipient = timesheet.Agreement.CareRecipientDisplayName;

            var model = expenses.Select(x => ExpenseViewModel.ToViewModel(x)).ToList();

            model.ForEach(x =>
            {
                if (x.Type == ExpenseType.Mileage && !string.IsNullOrWhiteSpace(x.ExtraInfo))
                {
                    x.Miles = decimal.Parse(x.ExtraInfo);
                }
                x.TimesheetID = id;
            });

            return(PartialView("_ExpensesModal", model));
        }
Exemplo n.º 2
0
        public IHttpActionResult Get(int id)
        {
            var expense = _repository.GetById(id);

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

            return(Ok(ExpenseViewModel.ToViewModel(expense)));
        }
Exemplo n.º 3
0
        public IHttpActionResult Get()
        {
            var result = _repository.All().Select(e => ExpenseViewModel.ToViewModel(e));

            return(Ok(result));
        }