Exemple #1
0
        public async Task <ActionResult> Index(string team, string userId, string publicationId, int?opeId, bool partial = false)
        {
            //check if user can create audit for inspection
            var currentUserId = Convert.ToInt32(System.Web.HttpContext.Current.User.Identity.GetUserId());
            var currentAudit  = await _prepareService.GetActiveAudit(currentUserId);

            var inspections = (await _prepareService.GetLastPublications((int)PublishModeEnum.Inspection))
                              .SelectMany(p => p.Inspections)
                              .OrderByDescending(i => i.StartDate)
                              .ToList();

            ViewBag.AllowCreateAudit = currentAudit == null;

            if (team == null && userId == null && publicationId == null)
            {
                var model = await InspectionMapper.ToInspectionManageViewModel(inspections);

                model.CurrentAuditInspectionId = currentAudit != null ? currentAudit.InspectionId : 0;
                model.IsCurrentAuditStarted    = currentAudit != null && currentAudit.AuditItems != null?currentAudit.AuditItems.Any() : false;

                model.Question = currentAudit != null ? currentAudit.Survey.Name : "";
                if (partial)
                {
                    return(PartialView(model));
                }
                return(View(model));
            }
            else
            {
                var(Users, Teams) = await _applicationUsersService.GetUsersTeams("0", "All", KnownRoles.Operator);

                var model = await InspectionMapper.ToInspectionManageViewModel(inspections, team, userId, publicationId);

                model.CurrentAuditInspectionId = currentAudit != null ? currentAudit.Id : 0;
                model.IsCurrentAuditStarted    = currentAudit != null && currentAudit.AuditItems != null?currentAudit.AuditItems.Any() : false;

                model.Question = currentAudit != null ? currentAudit.Survey.Name : "";
                var inspectionPublications = await _prepareService.GetLastPublicationsForFilter((int)PublishModeEnum.Inspection);

                var teams        = Teams.Select(t => t.Id).ToList();
                var operators    = Users.Select(u => u.UserId).ToList();
                var publications = inspectionPublications.Select(p => p.PublicationId.ToString()).ToList();
                model.selectedIndexTeam        = (team == "0") ? 0 : teams.IndexOf(Convert.ToInt16(team)) + 1;
                model.selectedIndexOperator    = (userId == "0") ? 0 : operators.IndexOf(Convert.ToInt16(userId)) + 1;
                model.selectedIndexPublication = (publicationId == "0") ? 0 : publications.IndexOf(publicationId) + 1;
                if (partial)
                {
                    return(PartialView(model));
                }
                return(View(model));
            }
        }
Exemple #2
0
        public async Task ExportToExcel(string GridModel, string gridId, int id, string process)
        {
            ExcelExport    exp = new ExcelExport();
            GridProperties obj = (GridProperties)Syncfusion.JavaScript.Utils.DeserializeToModel(typeof(GridProperties), GridModel);

            //Clear if there are any filter columns
            //syncfusion bug in exporting while in filter mode
            obj.FilterSettings.FilteredColumns.Clear();
            grid  = gridId;
            count = 0;
            if (gridId == "InspectionDetail")
            {
                var inspection = await _prepareService.GetInspection(id);

                // Retrieve all the action of the publication
                var actionSorted = inspection.Publication.PublishedActions.Distinct()
                                   .OrderBy(a => a.WBSParts, new WBSPartsComparer())
                                   .ToList();

                var inspectionSteps = GetInspectionStepAndChilds(inspection, actionSorted);
                var model           = InspectionMapper.ToInspectionViewModel(inspection, inspectionSteps, new List <Anomaly>());
                var dataSource      = model.Steps.ToList();
                inspectionStepViewModelData = dataSource;
                var currentDate = DateTime.Today.ToShortDateString().Replace("/", "-");
                obj.ServerExcelQueryCellInfo = QueryCellInfo;
                exp.Export(obj, dataSource, LocalizedStrings.GetString("Inspection") + " " + process + " " + currentDate + ".xlsx", ExcelVersion.Excel2013, false, false, "flat-saffron");
            }
            if (gridId == "InspectionManage")
            {
                var inspections = await _prepareService.GetInspections();

                var model = await InspectionMapper.ToInspectionManageViewModel(inspections);

                var dataSource = model.Inspections.ToList();
                inspectionViewModelData = dataSource;
                var currentDate = DateTime.Today.ToShortDateString().Replace("/", "-");
                obj.ServerExcelQueryCellInfo = QueryCellInfo;
                exp.Export(obj, dataSource, LocalizedStrings.GetString("Inspection") + " " + currentDate + ".xlsx", ExcelVersion.Excel2013, false, false, "flat-saffron");
            }
            if (gridId == "Anomaly")
            {
                var inspection = await _prepareService.GetInspection(id);

                var anomalies = await _prepareService.GetAnomalies(id);

                var model       = InspectionMapper.ToInspectionViewModel(inspection, new List <InspectionStep>(), anomalies);
                var dataSource  = model.Anomalies.ToList();
                var currentDate = DateTime.Today.ToShortDateString().Replace("/", "-");
                exp.Export(obj, dataSource, LocalizedStrings.GetString("Anomaly") + " " + process + " " + currentDate + ".xlsx", ExcelVersion.Excel2013, false, false, "flat-saffron");
            }
        }