public ActionResult AgedExceptionsUser(AgedExceptionsViewModel model)
        {
            model.IsManager = false;
            model.PrepCode  = this.PrepCode;

            return(AgedExceptionInternal(model));
        }
        private ActionResult AgedExceptionsResultsToFile(AgedExceptionsViewModel model)
        {
            MemoryStream output  = new MemoryStream();
            StreamWriter writer  = new StreamWriter(output, Encoding.UTF8);
            var          mgr     = new AgedExceptionsManager();
            var          results = mgr.GetAgedExceptionsOverThree(model.DateFrom, model.DateTo, model.PrepCode);

            bool wroteHeader = false;

            foreach (var result in results)
            {
                var type  = result.GetType();
                var props = type.GetProperties();

                if (!wroteHeader)
                {
                    // Replace some column names based on service.
                    var keys = props.Select(x => x.Name).ToArray();
                    writer.Write(string.Join(";", keys));
                    writer.WriteLine();
                    writer.WriteLine();
                    wroteHeader = true;
                }
                var values = props.Select(x => x.GetValue(result, null)).ToArray();
                writer.Write(string.Join(";", values));
                writer.WriteLine();
            }

            writer.Flush();
            output.Position = 0;

            return(File(output, "text/comma-separated-values", "AgedExceptionsUserReport.csv"));
        }
        public ActionResult AgedExceptionsUser(string ACT)
        {
            var model = new AgedExceptionsViewModel();

            var roleModel = this.RoleList;

            model.IsManager = false;
            model.PrepCode  = this.PrepCode;

            return(View("AgedExceptions", model));
        }
        public ActionResult AgedExceptions(AgedExceptionsViewModel model)
        {
            var roleModel = this.RoleList;

            // Only allow those with the mgmt reports role.
            if (roleModel != null && roleModel.HasMgtReportsRole)
            {
                model.IsManager = true;
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }

            return(AgedExceptionInternal(model));
        }
        private ActionResult AgedExceptionInternal(AgedExceptionsViewModel model)
        {
            // Did the user ask to save to file?
            if (model.SaveToFile == "true")
            {
                // Return a CSV formatted file.
                return(AgedExceptionsResultsToFile(model));
            }

            // Fall-through common path: search by date range and PrepCode.
            var mgr = new AgedExceptionsManager();

            model.AgedExceptionTotals    = mgr.GetAgedExceptionTotals(model.DateFrom, model.DateTo, model.PrepCode).ToList();
            model.AgedExceptionSummaries = mgr.GetAgedExceptionSummary().ToList();

            // Reset the detail view.
            model.ErrCode = "";
            return(View("AgedExceptions", model));
        }
        public ActionResult AgedExceptions(string ACT)
        {
            var model = new AgedExceptionsViewModel();

            var roleModel = this.RoleList;

            // Only allow those with the mgmt reports role.
            if (roleModel != null && roleModel.HasMgtReportsRole)
            {
                model.IsManager = true;
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
            model.PrepCode = this.PrepCode;

            return(View("AgedExceptions", model));
        }
        public ActionResult AgedExceptionsDetail([DataSourceRequest] DataSourceRequest request, AgedExceptionsViewModel search)
        {
            var mgr    = new AgedExceptionsManager();
            var items  = mgr.FetchAgedExceptionsDetail(search).AsQueryable();
            var result = items.ToDataSourceResult(request);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }