Exemplo n.º 1
0
        public ActionResult GridPreservationVerify([DataSourceRequest] DataSourceRequest request)
        {
            var result = new DataSourceResult();

            try
            {
                int total = 0;
                int skip  = (request.Page - 1) * request.PageSize;
                int take  = request.PageSize;

                if (skip < 0)
                {
                    skip = 0;
                }

                var service = new PreservationService();

                const int ARCHIVES_TAKE = 5;
                int       archiveSkip = 0, totalArchives;

                List <DocumentArchive>   archivi         = null;
                CustomerCompanyViewModel customerCompany = Session["idCompany"] as CustomerCompanyViewModel;

                if (WCFUtility.GetSettingValue("DBAdminLoginConnection") == "false")
                {
                    DocumentCondition            conditions     = new DocumentCondition();
                    List <DocumentSortCondition> sortConditions = new List <DocumentSortCondition>();
                    conditions.DocumentAttributeConditions = new System.ComponentModel.BindingList <DocumentCondition>();
                    conditions.DocumentAttributeConditions.Add(new DocumentCondition()
                    {
                        Name = "IsLegal", Value = 1, Operator = Library.Common.Enums.DocumentConditionFilterOperator.IsEqualTo, Condition = Library.Common.Enums.DocumentConditionFilterCondition.And
                    });
                    if (request.Filters != null)
                    {
                        foreach (var item in request.Filters)
                        {
                            //conditions.DocumentAttributeConditions.Add(new DocumentCondition { Name = item., Value = item.Value, Operator = Library.Common.Enums.DocumentConditionFilterOperator.Contains, Condition = Library.Common.Enums.DocumentConditionFilterCondition.And });
                        }
                    }
                    if (request.Sorts != null)
                    {
                        foreach (var item in request.Sorts)
                        {
                            sortConditions.Add(new DocumentSortCondition {
                                Name = item.Member, Dir = item.SortDirection
                            });
                        }
                    }
                    else
                    {
                        sortConditions.Add(new DocumentSortCondition {
                            Name = "Name", Dir = "ASC"
                        });
                    }

                    archivi = ArchiveService.GetArchives(skip, take, conditions, sortConditions, out total, customerCompany.CompanyId).ToList();
                }
                else
                {
                    archivi = UserArchive.GetUserArchivesPaged(User.Identity.Name, archiveSkip, ARCHIVES_TAKE, out totalArchives, customerCompany.CompanyId);

                    if (archivi.Count < totalArchives)
                    {
                        for (archiveSkip += ARCHIVES_TAKE; archiveSkip < totalArchives; archiveSkip += ARCHIVES_TAKE)
                        {
                            archivi.AddRange(UserArchive.GetUserArchivesPaged(User.Identity.Name, archiveSkip, ARCHIVES_TAKE, out totalArchives, customerCompany.CompanyId));
                        }
                    }

                    if (archivi.Any())
                    {
                        result.Data = service.GetPreservationVerify(archivi.Select(x => x.IdArchive).ToArray <Guid>(), skip, take, out total, null);
                    }
                    else
                    {
                        result.Data = archivi;
                    }
                }
                result.Total = total;
            }
            catch (Exception ex)
            {
                result.Errors = ex;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }