Пример #1
0
        public ServiceMarriageObject Search(MarriageFilterTypes filterMode, MarriageSearchFilter marriageSearchFilter, DataShaping shaping, IValidator validator = null)
        {
            var serviceMarriageObject = new ServiceMarriageObject();

            if (!_security.IsvalidSelect())  serviceMarriageObject.ErrorStatus = "Invalid permission to select";

            if (validator != null && !validator.ValidEntry())  serviceMarriageObject.ErrorStatus += " Validation failed: " + validator.GetErrors();

            if (serviceMarriageObject.ErrorStatus.Length == 0)
            {

                if (shaping.Column.Contains("MarriageDate DESC"))
                {
                    shaping.Column = "MarriageYear DESC";
                }
                else if (shaping.Column.Contains("MarriageDate"))
                {
                    shaping.Column = "MarriageYear";
                }

                switch (filterMode)
                {
                    case MarriageFilterTypes.Duplicates:
                        serviceMarriageObject = marriageSearchFilter.ParentId != Guid.Empty
                                                    ? _marriagesDll.GetDataByUniqueRef(marriageSearchFilter.ParentId)
                                                                   .ToServiceMarriageObject(shaping.Column, shaping.RecordPageSize,
                                                                                            shaping.RecordStart)
                                                    : new ServiceMarriageObject();
                        break;
                    case MarriageFilterTypes.Standard:
                        serviceMarriageObject =
                            _marriagesDll.GetFilteredMarriages(marriageSearchFilter)
                                         .ToServiceMarriageObject(shaping.Column, shaping.RecordPageSize, shaping.RecordStart);
                        break;

                    case MarriageFilterTypes.IdList:
                        serviceMarriageObject = _marriagesDll.GetByListId(marriageSearchFilter.Ids).ToServiceMarriageObject(shaping.Column, shaping.RecordPageSize, shaping.RecordStart);
                        break;

                }

            }
            return serviceMarriageObject;
        }
        public static ServiceMarriageObject ToServiceMarriageObject(this IList<MarriageResult> marriages, string sortColumn, int pageSize, int pageNumber)
        {
            var smo = new ServiceMarriageObject
            {
                serviceMarriages = marriages.OrderBy(sortColumn).Select(m => new ServiceMarriageLookup
                {
                    MarriageId = m.MarriageId,
                    MaleCName = m.MaleCName,
                    MaleSName = m.MaleSName,
                    FemaleCName = m.FemaleCName,
                    FemaleSName = m.FemaleSName,
                    MarriageDate = m.MarriageYear.ToString(),
                    MarriageLocation = m.MarriageLocation,
                    Witnesses = m.Witnesses,
                    UniqueRef = m.UniqueRef.ToString(),
                    Sources = m.MarriageSource,
                    TotalEvents = m.MarriageTotalEvents.ToString(),
                    LinkedTrees = m.SourceTrees,
                    Notes = m.Notes
                }).ToList()
            };

            smo.Total = smo.serviceMarriages.Count;

            if (pageSize != 0)
            {
                smo.Batch = pageNumber;
                smo.BatchLength = pageSize;
                smo.serviceMarriages = smo.serviceMarriages.Skip(pageNumber * pageSize).Take(pageSize).ToList();
            }

            return smo;
        }
        public IHttpActionResult GetMarriages(string uniqref, string malecname, string malesname, string femalecname,
            string femalesname, string location, string lowerDate, string upperDate, string sourceFilter, string parishFilter, string marriageWitness,
            string pno, string psize, string sortcol = "")
        {
            var serviceMarriageObject = new ServiceMarriageObject();

            string retVal = "";

            try
            {

                Guid parentId = uniqref.ToGuid();

                if (parentId == Guid.Empty)
                {
                    var marriageFilter = new MarriageSearchFilter()
                    {
                        Ids = new List<Guid>(),
                        MaleCName = malecname ?? "",
                        MaleSName = malesname ?? "",
                        FemaleCName = femalecname ?? "",
                        FemaleSName = femalesname ?? "",
                        Location = location ?? "",
                        LowerDate = lowerDate.ToInt32(),
                        UpperDate = upperDate.ToInt32(),
                        Witness = marriageWitness ?? "",
                        Parish = parishFilter ?? "",
                        Source = sourceFilter ?? "",
                        ParentId = Guid.Empty
                    };

                    var marriageValidation = new MarriageSearchValidator(marriageFilter);

                    serviceMarriageObject = _marriageSearch.Search(MarriageFilterTypes.Standard, marriageFilter,
                                  new DataShaping()
                                  {
                                      Column = sortcol ?? "",
                                      RecordPageSize = psize.ToInt32(),
                                      RecordStart = pno.ToInt32()
                                  }, marriageValidation);

                }
                else
                {
                    serviceMarriageObject = _marriageSearch.Search(MarriageFilterTypes.Duplicates, new MarriageSearchFilter() { ParentId = parentId },
                                  new DataShaping()
                                  {
                                      Column = sortcol ?? "",
                                      RecordPageSize = psize.ToInt32(),
                                      RecordStart = 0
                                  });

                }

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

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

            return Ok(serviceMarriageObject);
        }
Пример #4
0
        public ServiceMarriageObject GetMarriages(string uniqref, string malecname, string malesname, string femalecname,
            string femalesname, string location, string lowerDate, string upperDate, string sourceFilter, string parishFilter, string marriageWitness,
            string page_number, string page_size, string sort_col)
        {
            //var iModel = new MarriageSearch(new Security(new WebUser()));

            var serviceMarriageObject = new ServiceMarriageObject();

            string retVal = "";

            try
            {

                Guid parentId = uniqref.ToGuid();

                if (parentId == Guid.Empty)
                {
                    var marriageFilter = new MarriageSearchFilter()
                        {
                            MaleCName = malecname,
                            MaleSName = malesname,
                            FemaleCName = femalecname,
                            FemaleSName = femalesname,
                            Location = location,
                            LowerDate = lowerDate.ToInt32(),
                            UpperDate = upperDate.ToInt32(),
                            Witness = marriageWitness,
                            Parish = parishFilter,
                            Source = sourceFilter,
                            ParentId = Guid.Empty
                        };

                    var marriageValidation = new MarriageSearchValidator(marriageFilter);

                    serviceMarriageObject = _marriageSearch.Search(MarriageFilterTypes.Standard, marriageFilter,
                                  new DataShaping()
                                      {
                                          Column = sort_col,
                                          RecordPageSize = page_size.ToInt32(),
                                          RecordStart = page_number.ToInt32()
                                      }, marriageValidation);

                }
                else
                {
                    serviceMarriageObject = _marriageSearch.Search(MarriageFilterTypes.Duplicates, new MarriageSearchFilter() { ParentId = parentId },
                                  new DataShaping()
                                  {
                                      Column = sort_col,
                                      RecordPageSize = page_size.ToInt32(),
                                      RecordStart = 0
                                  });

                }

            }
            catch (Exception ex1)
            {
                retVal = "Exception: " + ex1.Message;
            }
            finally
            {
                if (retVal != "") retVal += Environment.NewLine;
                serviceMarriageObject.ErrorStatus = retVal;
            }

            return serviceMarriageObject;
        }
        public IHttpActionResult GetMarriages(string ids)
        {
            var marriageFilter = new MarriageSearchFilter()
            {
                Ids = ids.ParseToGuidList()
            };
            var marriageValidation = new MarriageSearchValidator(marriageFilter);
            // ahouls use search function here
            string retVal = "";

            var serviceMarriageObject = new ServiceMarriageObject();

            try
            {

                serviceMarriageObject = _marriageSearch.Search(MarriageFilterTypes.IdList, marriageFilter,
                                  new DataShaping()
                                  {
                                      Column = "",
                                      RecordPageSize = 25,
                                      RecordStart = 0
                                  }, marriageValidation);

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

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

            return Ok(serviceMarriageObject );
        }