Esempio n. 1
0
        public List<ServiceSource> FillTreeSources(SourceSearchFilter description)
        {
            using (var context = new GeneralModelContainer())
            {
                List<ServiceSource> retVal;

                if (description.Description == "")
                    retVal =
                        context.Sources.Where(o => o.SourceMappings.Any(p => p.SourceType.SourceTypeId == 39))
                            .Select(s => new ServiceSource
                            {
                                SourceDesc = s.SourceDescription,
                                SourceId = s.SourceId,
                                SourceRef = s.SourceRef,
                                SourceYear = s.SourceDate.GetValueOrDefault(),
                                SourceYearTo = s.SourceDateTo.GetValueOrDefault(),
                                UserId = s.UserId
                            }).ToList();
                else
                    retVal =
                        context.Sources.Where(
                            o =>
                                o.SourceMappings.Any(p => p.SourceType.SourceTypeId == 39) &&
                                o.SourceDescription.Contains(description.Description)).Select(s => new ServiceSource
                                {
                                    SourceDesc = s.SourceDescription,
                                    SourceId = s.SourceId,
                                    SourceRef = s.SourceRef,
                                    SourceYear = s.SourceDate.GetValueOrDefault(),
                                    SourceYearTo = s.SourceDateTo.GetValueOrDefault(),
                                    UserId = s.UserId
                                }).ToList();

                if (description.IncludeDefaultPerson)
                {
                    foreach (var ss in retVal)
                    {
                        var sourceMap =
                            context.SourceMappings.FirstOrDefault(
                                o => o.Source.SourceId == ss.SourceId && o.SourceType.SourceTypeId == 39);

                        if (sourceMap != null)
                        {
                            ss.DefaultPerson = sourceMap.Person != null ? sourceMap.Person.Person_id : Guid.Empty;
                        }
                        else
                            ss.DefaultPerson = Guid.Empty;
                    }

                }

                return retVal;
            }
        }
Esempio n. 2
0
        public List<ServiceSource> FillSourceTableByFilter(SourceSearchFilter ssf, DataShaping dataShaping)
        {
            List<ServiceSource> result;
            #region booleans
            bool isCopyHoldLocal;
            bool isCopyHoldLocalAlt;

            if (ssf.CopyHeld == null)
            {
                isCopyHoldLocal = false;
                isCopyHoldLocalAlt = true;
            }
            else
            {
                isCopyHoldLocal = ssf.CopyHeld.Value;
                isCopyHoldLocalAlt = ssf.CopyHeld.Value;
            }

            bool isViewedLocal;
            bool isViewedLocalAlt;

            if (ssf.Viewed == null)
            {
                isViewedLocal = false;
                isViewedLocalAlt = true;
            }
            else
            {
                isViewedLocal = ssf.Viewed.Value;
                isViewedLocalAlt = ssf.Viewed.Value;
            }

            bool isThackrayLocalFound;
            bool isThackrayLocalFoundAlt;

            if (ssf.ThackrayFound == null)
            {
                isThackrayLocalFound = false;
                isThackrayLocalFoundAlt = true;
            }
            else
            {
                isThackrayLocalFound = ssf.ThackrayFound.Value;
                isThackrayLocalFoundAlt = ssf.ThackrayFound.Value;
            }

            #endregion

            ssf.SourceTypes.RemoveAll(p => p == 0);

            string listOfSourcesStr =ssf.SourceTypes.ParseToCSV();

            int sourceL = ssf.LrStart;
            int sourceU = ssf.LrEnd;

            int sourceToL = ssf.UrStart;

            int sourceToU = ssf.UrEnd;

            using (var context = new GeneralModelContainer())
            {

                if (listOfSourcesStr == "")
                {
                    dataShaping.TotalRecords =
                        context.Sources.Count(
                            o => (o.IsCopyHeld == isCopyHoldLocal || o.IsCopyHeld == isCopyHoldLocalAlt) &&
                                 (o.IsThackrayFound == isThackrayLocalFound ||
                                  o.IsThackrayFound == isThackrayLocalFoundAlt) &&
                                 o.SourceDescription.Contains(ssf.Description) &&
                                 (o.IsViewed == isViewedLocal || o.IsViewed == isViewedLocalAlt) &&
                                 o.OriginalLocation.Contains(ssf.OriginalLocation) &&

                                 o.SourceDate >= sourceL && o.SourceDate <= sourceU &&
                                 o.SourceDateTo >= sourceToL && o.SourceDateTo <= sourceToU &&

                                 o.SourceRef.Contains(ssf.Ref));

                    result =
                        context.Sources.Where(
                            o => (o.IsCopyHeld == isCopyHoldLocal || o.IsCopyHeld == isCopyHoldLocalAlt) &&
                                 (o.IsThackrayFound == isThackrayLocalFound ||
                                  o.IsThackrayFound == isThackrayLocalFoundAlt) &&
                                 o.SourceDescription.Contains(ssf.Description) &&
                                 (o.IsViewed == isViewedLocal || o.IsViewed == isViewedLocalAlt) &&
                                 o.OriginalLocation.Contains(ssf.OriginalLocation) &&

                                 o.SourceDate >= sourceL && o.SourceDate <= sourceU &&
                                 o.SourceDateTo >= sourceToL && o.SourceDateTo <= sourceToU &&
                                 o.SourceMarriageCount >= ssf.MarriageCount &&
                                 o.SourcePersonCount >= ssf.PersonCount &&
                                 o.SourceRef.Contains(ssf.Ref)).Select(p => new ServiceSource
                                 {
                                     SourceDesc = p.SourceDescription,
                                     SourceId = p.SourceId,
                                     SourceRef = p.SourceRef,
                                     SourceYear = p.SourceDate,
                                     SourceYearTo = p.SourceDateTo,
                                     MarriageCount = p.SourceMarriageCount,
                                     PersonCount = p.SourcePersonCount
                                 })
                            .OrderBy(o => o.SourceId)
                            .Skip(dataShaping.RecordStart*dataShaping.RecordPageSize)
                            .Take(dataShaping.RecordPageSize)
                            .ToList();
                }
                else
                {
                    result = context.GetSourcesBySourceTypes(
                        ssf.Ref,
                        sourceToU, sourceL, sourceToL, sourceU,
                        1,
                        ssf.OriginalLocation,
                        new DateTime(2050, 1, 1),
                        new DateTime(1920, 1, 1),
                        isThackrayLocalFound,
                        isThackrayLocalFoundAlt,
                        isViewedLocal,
                        isViewedLocalAlt,
                        isCopyHoldLocal,
                        isCopyHoldLocalAlt,
                        listOfSourcesStr, ssf.MarriageCount, ssf.PersonCount).Select(p => new ServiceSource
                        {
                            SourceDesc = p.SourceDescription,
                            SourceId = p.SourceId,
                            SourceRef = p.SourceRef,
                            SourceYear = p.SourceDate.GetValueOrDefault(),
                            SourceYearTo = p.SourceDateTo.GetValueOrDefault(),
                            MarriageCount = p.SourceMarriageCount,
                            PersonCount = p.SourcePersonCount
                        }).ToList();

                    dataShaping.TotalRecords = result.Count();

                    result =
                        result.Skip(dataShaping.RecordStart*dataShaping.RecordPageSize)
                            .Take(dataShaping.RecordPageSize)
                            .ToList();
                }

                return ssf.FileCount.ToInt32() == 0
                    ? result.Where(o => o.FileCount == 0).ToList()
                    : result.Where(o => o.FileCount >= ssf.FileCount.ToInt32()).ToList();

            }
        }
        public List<string> GetSourceNames(string sourceIds)
        {
            var serviceSourceObject = new ServiceSourceObject();

            var iModel = new SourceSearch(new Security(new WebUser()));

            string retVal = "";
            try
            {
                var ssf = new SourceSearchFilter() { Sources = sourceIds.ParseToGuidList() };
                serviceSourceObject = iModel.Search(SourceSearchTypes.SourceIds, ssf, new DataShaping(){RecordPageSize = 0}, new SourceSearchValidator(ssf));
            }
            catch (Exception ex1)
            {
                retVal = "Exception: " + ex1.Message;
            }
            finally
            {
                if (retVal != "") retVal += Environment.NewLine;

                serviceSourceObject.ErrorStatus = retVal;
            }

            return serviceSourceObject.serviceSources.Select(p => p.SourceRef).ToList();
        }
        public ServiceSourceObject GetSources(string sourceTypes, string sourceRef, string sourceDesc, string origLoc,
            string dateLB, string toDateLB, string dateUB, string toDateUB, string fileCount, string isThackrayFound,
            string isCopyHeld, string isViewed, string isChecked, string page_number, string page_size, string sortColumn)
        {
            var serviceSourceObject = new ServiceSourceObject();

            string retVal = "";
            var ssf = new SourceSearchFilter()
                {
                    CensusSources1841 = false,
                    CensusPlaces1841 = false,
                    CopyHeld = isChecked.ToNullableBool() == true ? isCopyHeld.ToNullableBool() : null,
                    ThackrayFound = isChecked.ToNullableBool() == true ? isThackrayFound.ToNullableBool() : null,
                    Viewed = isChecked.ToNullableBool() == true ? isViewed.ToNullableBool() : null,
                    SourceTypes = sourceTypes.ParseToIntList(),
                    Ref = sourceRef,
                    Description = sourceDesc,
                    FromYear= (dateLB.ToInt32() + toDateLB.ToInt32()),
                    ToYear = (toDateUB.ToInt32() + dateUB.ToInt32()),
                    OriginalLocation = origLoc,
                    FileCount = fileCount,
                    UrStart = dateUB.ToInt32(),
                    UrEnd = toDateUB.ToInt32(),
                    LrStart = dateLB.ToInt32(),
                    LrEnd = toDateLB.ToInt32()
                };

            var iModel = new SourceSearch(new Security(new WebUser()));

            try
            {
                serviceSourceObject= iModel.Search(SourceSearchTypes.Standard, ssf, new DataShaping() { RecordStart = page_number.ToInt32(), RecordPageSize = page_size.ToInt32(), Column = sortColumn }, new SourceSearchValidator(ssf));
            }
            catch (Exception ex1)
            {
                retVal = "Exception: " + ex1.Message;
            }
            finally
            {
                if (retVal != "") retVal += Environment.NewLine;

                serviceSourceObject.ErrorStatus = retVal;
            }

            return serviceSourceObject;
        }
        public IHttpActionResult GetSources(string sourceTypes, string sourceRef, string sourceDesc, string origLoc,
            string dateLb, string toDateLb, string dateUb, string toDateUb, string fileCount, string isThackrayFound,
            string isCopyHeld, string isViewed, string isChecked, string pageNumber, string pageSize, string sortColumn)
        {
            ServiceSourceObject serviceSourceObject = new ServiceSourceObject();

            string retVal = "";
            var ssf = new SourceSearchFilter()
            {
                CensusSources1841 = false,
                CensusPlaces1841 = false,
                CopyHeld = isChecked.ToNullableBool() == true ? isCopyHeld.ToNullableBool() : null,
                ThackrayFound = isChecked.ToNullableBool() == true ? isThackrayFound.ToNullableBool() : null,
                Viewed = isChecked.ToNullableBool() == true ? isViewed.ToNullableBool() : null,
                SourceTypes = sourceTypes.ParseToIntList(),
                Ref = sourceRef ?? "",
                Description = sourceDesc ?? "",
                FromYear = (dateLb.ToInt32() + toDateLb.ToInt32()),
                ToYear = (toDateUb.ToInt32() + dateUb.ToInt32()),
                OriginalLocation = origLoc ?? "",
                FileCount = fileCount ?? "",
                UrStart = dateUb.ToInt32(),
                UrEnd = toDateUb.ToInt32(),
                LrStart = dateLb.ToInt32(),
                LrEnd = toDateLb.ToInt32()
            };

            var sourceSearch = new SourceSearch(new Security(new WebUser()));

            try
            {
                serviceSourceObject = sourceSearch.Search(SourceSearchTypes.Standard, ssf, new DataShaping() { RecordStart = pageNumber.ToInt32(), RecordPageSize = pageSize.ToInt32(), Column = sortColumn }, new SourceSearchValidator(ssf));
            }
            catch (Exception ex1)
            {
                retVal = "Exception: " + ex1.Message;
            }

            if (retVal != "")
            {
                return Content(HttpStatusCode.BadRequest, retVal);
            }

            return Ok(serviceSourceObject);
        }
        public List<CensusSource> Get1841CensusSources(Guid sourceId)
        {
            var serviceSourceObject = new ServiceSourceObject();
            var iModel = new SourceSearch(new Security(new WebUser()));

            string retVal = "";
            try
            {

                var ssf = new SourceSearchFilter() { Sources = new List<Guid>() { sourceId } };
                serviceSourceObject = iModel.Search(SourceSearchTypes.Censussource, ssf,new DataShaping(){RecordPageSize = 0},new SourceSearchValidator(ssf));

            }
            catch (Exception ex1)
            {
                retVal = "Exception: " + ex1.Message;
            }
            finally
            {

                serviceSourceObject.ErrorStatus = retVal;
            }

            return serviceSourceObject.CensusSources;
        }
        public IHttpActionResult GetSourceNames(string sourceIds)
        {
            var servicesources = new List<string>();

            var sourceSearch = new SourceSearch(new Security(new WebUser()));

            string retVal = "";

            try
            {
                var ssf = new SourceSearchFilter() { Sources = sourceIds.ParseToGuidList() };
                var serviceSourceObject = sourceSearch.Search(SourceSearchTypes.SourceIds, ssf, new DataShaping() { RecordPageSize = 0 }, new SourceSearchValidator(ssf));

                servicesources = serviceSourceObject.serviceSources.Select(p => p.SourceRef).ToList();
            }
            catch (Exception ex1)
            {
                retVal = "Exception: " + ex1.Message;
            }

            if (retVal != "")
            {
                return Content(HttpStatusCode.BadRequest, retVal);
            }

            return Ok(servicesources);
        }
        public IHttpActionResult Get1841CensusSources(Guid sourceId)
        {
            var serviceSourceObject = new ServiceSourceObject();
            var sourceSearch = new SourceSearch(new Security(new WebUser()));

            string retVal = "";
            try
            {

                var ssf = new SourceSearchFilter() { Sources = new List<Guid>() { sourceId } };
                serviceSourceObject = sourceSearch.Search(SourceSearchTypes.Censussource, ssf, new DataShaping() { RecordPageSize = 0 }, new SourceSearchValidator(ssf));

            }
            catch (Exception ex1)
            {
                retVal = "Exception: " + ex1.Message;
            }

            if (retVal != "")
            {
                return Content(HttpStatusCode.BadRequest, retVal);
            }

            return Ok(serviceSourceObject.CensusSources);
        }
 public SourceSearchValidator(SourceSearchFilter sourceSearchFilter)
 {
     _sourceSearchFilter = sourceSearchFilter;
 }
Esempio n. 10
0
        public void DeleteRecords(SourceSearchFilter sourceSearchFilter)
        {
            if (!_security.IsValidDelete()) throw new SecurityException("Missing delete permission");

            sourceSearchFilter.Sources.ForEach(s => _sourceDal.DeleteSource2(s));
        }
Esempio n. 11
0
        public ServiceSourceObject Search(SourceSearchTypes param, SourceSearchFilter sourceSearchFilter,DataShaping shaper, IValidator validator = null)
        {
            var sourcesDataTable = new ServiceSourceObject();

            if(validator== null)
                validator = new Validator();

            if (!_security.IsvalidSelect()) throw new SecurityException("Missing select permission");

            if (!validator.ValidEntry()) throw new InvalidDataException(validator.GetErrors());

            switch (param)
            {
                case SourceSearchTypes.Standard:
                    sourcesDataTable = _sourceDal.FillSourceTableByFilter(sourceSearchFilter, shaper).ToServiceSourceObject(shaper.Column, shaper.RecordPageSize, shaper.RecordStart, shaper.TotalRecords);
                    break;
                case SourceSearchTypes.Treesources:
                    sourcesDataTable = _sourceDal.FillTreeSources(sourceSearchFilter).ToServiceSourceObject(shaper.Column, shaper.RecordPageSize, shaper.RecordStart);
                    break;
                case SourceSearchTypes.Censussource:
                    sourcesDataTable.CensusSources = _sourceDal.Get1841CensuSources(!sourceSearchFilter.Sources.IsNullOrBelowMinSize() ? sourceSearchFilter.Sources.First() : Guid.Empty);
                    break;
                case SourceSearchTypes.SourceIds:
                    sourcesDataTable = _sourceDal.FillSourceTableBySourceIds(!sourceSearchFilter.Sources.IsNullOrBelowMinSize() ? sourceSearchFilter.Sources : new List<Guid>())
                        .ToServiceSourceObject(shaper.Column, shaper.RecordPageSize, shaper.RecordStart);
                    break;
            }

            return sourcesDataTable;
        }