public async Task <IActionResult> Index([FromBody] CaseRequestModel requestModel)
        {
            if (requestModel.TemplateId != null &&
                !await _permissionsService.CheckEform((int)requestModel.TemplateId,
                                                      AuthConsts.EformClaims.CasesClaims.CasesRead))
            {
                return(Forbid());
            }

            return(Ok(await _casesService.Index(requestModel)));
        }
Exemplo n.º 2
0
        public async Task <OperationDataResult <CaseListModel> > Index(CaseRequestModel requestModel)
        {
            try
            {
                var value    = _httpContextAccessor?.HttpContext.User?.FindFirstValue(ClaimTypes.NameIdentifier);
                var timeZone = _dbContext.Users.Single(x => x.Id == int.Parse(value)).TimeZone;
                if (string.IsNullOrEmpty(timeZone))
                {
                    timeZone = "Europe/Copenhagen";
                }

                TimeZoneInfo timeZoneInfo;

                try
                {
                    timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone);
                }
                catch
                {
                    timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("E. Europe Standard Time");
                }
                var core = await _coreHelper.GetCore();

                var caseList = await core.CaseReadAll(requestModel.TemplateId, null, null,
                                                      Constants.WorkflowStates.NotRemoved, requestModel.NameFilter,
                                                      requestModel.IsSortDsc, requestModel.Sort, requestModel.Offset, requestModel.PageSize, timeZoneInfo);

                var model = new CaseListModel()
                {
                    NumOfElements = caseList.NumOfElements,
                    PageNum       = caseList.PageNum,
                    Cases         = caseList.Cases
                };

                return(new OperationDataResult <CaseListModel>(true, model));
            }
            catch (Exception ex)
            {
                Log.LogException(ex.Message);
                Log.LogException(ex.StackTrace);
                return(new OperationDataResult <CaseListModel>(false, _localizationService.GetString("CaseLoadingFailed") + $" Exception: {ex.Message}"));
            }
        }
Exemplo n.º 3
0
        public OperationDataResult <CaseListModel> Index(CaseRequestModel requestModel)
        {
            try
            {
                var core     = _coreHelper.GetCore();
                var caseList = core.CaseReadAll(requestModel.TemplateId, null, null,
                                                Constants.WorkflowStates.NotRemoved, requestModel.NameFilter,
                                                requestModel.IsSortDsc, requestModel.Sort);
                var model = new CaseListModel()
                {
                    NumOfElements = 40,
                    PageNum       = requestModel.PageIndex,
                    Cases         = caseList
                };

                return(new OperationDataResult <CaseListModel>(true, model));
            }
            catch (Exception)
            {
                return(new OperationDataResult <CaseListModel>(false, "Case loading failed"));
            }
        }
        public async Task <OperationDataResult <CaseListModel> > Index(CaseRequestModel requestModel)
        {
            try
            {
                var core = await _coreHelper.GetCore();

                var sdkDbContext = core.DbContextHelper.GetDbContext();

                // get base query
                var query = sdkDbContext.Cases.Join(sdkDbContext.Sites, c => c.SiteId, s => s.Id, (
                                                        (c, s) => new
                {
                    c.Id,
                    c.DoneAt,
                    SiteName = s.Name,
                    SiteId = s.Id,
                    c.WorkflowState,
                    c.CheckListId,
                    c.FieldValue1,
                    c.FieldValue2,
                    c.FieldValue3,
                    c.FieldValue4,
                    c.FieldValue5,
                    c.FieldValue6,
                    c.FieldValue7,
                    c.FieldValue8,
                    c.FieldValue9,
                    c.FieldValue10,
                    c.Type,
                    c.Status,
                    c.IsArchived,
                    c.CaseUid,
                    c.MicrotingUid,
                    c.MicrotingCheckUid,
                    c.CreatedAt,
                    c.DoneAtUserModifiable,
                    c.Custom,
                    c.Version,
                    c.UpdatedAt,
                    c.UnitId
                }))
                            //.Include(x => x.Worker)
                            .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                            .Where(x => x.DoneAtUserModifiable != null)
                            .Where(x => x.CheckListId == requestModel.TemplateId);

                // add sort and filtering
                var nameFields = new List <string> {
                    "FieldValue1", "FieldValue2", "FieldValue3", "FieldValue4", "FieldValue5", "FieldValue6", "FieldValue7", "FieldValue8", "FieldValue9", "FieldValue10", "Id", "DoneAt", "SiteName"
                };
                query = QueryHelper.AddFilterAndSortToQuery(query, requestModel, nameFields);

                //get total
                var total = await query.Select(x => x.Id).CountAsync();

                // pagination
                query = query
                        .Skip(requestModel.Offset)
                        .Take(requestModel.PageSize);

                // select cases
                var cases = await query.Select(x => new Case
                {
                    FieldValue1          = x.FieldValue1,
                    FieldValue2          = x.FieldValue2,
                    FieldValue3          = x.FieldValue3,
                    FieldValue4          = x.FieldValue4,
                    FieldValue5          = x.FieldValue5,
                    FieldValue6          = x.FieldValue6,
                    FieldValue7          = x.FieldValue7,
                    FieldValue8          = x.FieldValue8,
                    FieldValue9          = x.FieldValue9,
                    FieldValue10         = x.FieldValue10,
                    CaseType             = x.Type,
                    CaseUId              = x.CaseUid,
                    CheckUIid            = x.MicrotingCheckUid,
                    CreatedAt            = x.CreatedAt,
                    Custom               = x.Custom,
                    DoneAt               = x.DoneAt,
                    DoneAtUserModifiable = x.DoneAtUserModifiable,
                    Id            = x.Id,
                    IsArchived    = x.IsArchived,
                    MicrotingUId  = x.MicrotingUid,
                    SiteId        = x.SiteId,
                    Status        = x.Status,
                    TemplatId     = x.CheckListId,
                    UnitId        = x.UnitId,
                    UpdatedAt     = x.UpdatedAt,
                    Version       = x.Version,
                    WorkflowState = x.WorkflowState,
                    SiteName      = x.SiteName,
                    WorkerName    = x.SiteName,
                })
                            .ToListAsync();

                var model = new CaseListModel
                {
                    NumOfElements = total,
                    Cases         = cases,
                };

                return(new OperationDataResult <CaseListModel>(true, model));
            }
            catch (Exception ex)
            {
                Log.LogException(ex.Message);
                Log.LogException(ex.StackTrace);
                return(new OperationDataResult <CaseListModel>(false, _localizationService.GetString("CaseLoadingFailed") + $" Exception: {ex.Message}"));
            }
        }