Beispiel #1
0
        public IList <CourtItem> Search(string name, string type)
        {
            IList <CourtItem> result = (from court in db.Courts
                                        join t1 in db.CourtTypes on court.CourtTypeID equals t1.CourtTypeID into r1
                                        from courtType in r1.DefaultIfEmpty()
                                        select new
            {
                CourtTable = court,
                CourtTypeTable = courtType
            }).Select(list => new CourtItem
            {
                CourtID       = list.CourtTable.CourtID,
                CourtName     = list.CourtTable.CourtName,
                CourtTypeID   = list.CourtTable.CourtTypeID,
                CourtTypeName = list.CourtTypeTable.CourtTypeName
            }).ToList();

            if (!string.IsNullOrEmpty(name))
            {
                result = result.Where(p => p.CourtName.StartsWith(name, StringComparison.OrdinalIgnoreCase)).ToList();
            }
            if (!string.IsNullOrEmpty(type))
            {
                int       id        = Convert.ToInt32(type);
                CourtType courtType = db.CourtTypes.Find(id);
                result = result.Where(p => p.CourtTypeName == courtType.CourtTypeName).ToList();
            }
            return(result);
        }
        public CourtType GetCourtType(int CourtTypeID)
        {
            CourtType dbItem = db.CourtTypes.Find(CourtTypeID);
            CourtType item   = new CourtType
            {
                CourtTypeID   = dbItem.CourtTypeID,
                CourtTypeName = dbItem.CourtTypeName
            };

            return(item);
        }