Beispiel #1
0
        public JsonResult GetAssignments(BootGridRequest request)
        {
            int?statusId = null;

            if (request.Params != null)
            {
                if (request.Params.Keys.Contains("StatusId") && !string.IsNullOrEmpty(request.Params["StatusId"]))
                {
                    statusId = int.Parse(request.Params["StatusId"]);
                }
            }

            var isAdmin       = User.IsInRole("admin");
            var assignmentsVm = Mapper.Map <IEnumerable <AssignmentViewModel> >(_assignmentService.AllIncluding(item => item.AssignmentStatus).Where(item => (item.CustomerId == CustomerId || isAdmin) && (!statusId.HasValue || item.StatusId == statusId.Value) && ((!isAdmin || item.StatusId > 2))));
            var response      = new BootGridResponse <AssignmentViewModel>(request, assignmentsVm);

            foreach (var item in response.Rows)
            {
                item.InvoicesCount = _invoiceService.All.Count(i => i.AssignmentId == item.Id);
                item.Adjustment    = _overpaymentService.FindBy(e => e.OriginInvoice.AssignmentId == item.Id && e.StatusId == 1).Sum(e => (decimal?)e.Amount);
            }
            return(Json(response));
        }