示例#1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string searchTerm = context.Request["term"];
            string searchType = context.Request["type"];
            JavaScriptSerializer        serializer = new JavaScriptSerializer();
            List <AutoCompleteResponse> result     = new List <AutoCompleteResponse>();

            AutocompleteType type = (AutocompleteType)Enum.Parse(typeof(AutocompleteType), searchType, true);

            if (!searchTerm.IsEmpty() && !searchType.IsEmpty())
            {
                switch (type)
                {
                default:
                {
                    context.Response.Write(string.Empty);
                    break;
                }

                case AutocompleteType.Logo:
                case AutocompleteType.PlayerPhoto:
                {
                    DirectoryInfo logosDirInfo = new DirectoryInfo(Constants.Paths.DropBoxPath);
                    if (logosDirInfo.Exists)
                    {
                        FileInfo[] files = logosDirInfo.GetFiles(searchTerm + "*");
                        result.AddRange(files.Select(f => new AutoCompleteResponse {
                                id = 1, value = f.Name
                            }));
                        context.Response.Write(serializer.Serialize(result));
                    }
                    else
                    {
                        context.Response.Write(string.Empty);
                    }

                    break;
                }

                case AutocompleteType.Club:
                {
                    using (UaFootball_DBDataContext db = DBManager.GetDB())
                    {
                        IQueryable <AutoCompleteResponse> searchMatches = db.Clubs.Where(c => c.Club_Name.Contains(searchTerm)).Select(c => new AutoCompleteResponse {
                                id = c.Club_ID, value = string.Concat(c.Club_Name, " (", c.City.City_Name, ")")
                            });
                        result.AddRange(searchMatches);
                        context.Response.Write(serializer.Serialize(result));
                    }
                    break;
                }

                case AutocompleteType.NationalTeam:
                {
                    using (UaFootball_DBDataContext db = DBManager.GetDB())
                    {
                        var searchMatches =
                            from natTeam in db.NationalTeams
                            join country in db.Countries on natTeam.Country_Id equals country.Country_ID
                            where country.Country_Name.Contains(searchTerm) && natTeam.NationalTeamType_Cd == "NAT"
                            select new { id = natTeam.NationalTeam_Id, value = country.Country_Name, code = natTeam.NationalTeamType_Cd };

                        foreach (var item in searchMatches)
                        {
                            result.Add(new AutoCompleteResponse {
                                    id = item.id, value = item.value + " " + UIHelper.FormatNationalTeamType(item.code)
                                });
                        }

                        context.Response.Write(serializer.Serialize(result));
                    }
                    break;
                }

                case AutocompleteType.Referee:
                {
                    using (UaFootball_DBDataContext db = DBManager.GetDB())
                    {
                        IQueryable <AutoCompleteResponse> searchMatches = db.Referees.Where(r => r.LastName.Contains(searchTerm)).Select(r => new AutoCompleteResponse {
                                id = r.Referee_Id, value = r.FirstName + " " + r.LastName
                            });
                        result.AddRange(searchMatches);
                        context.Response.Write(serializer.Serialize(result));
                    }
                    break;
                }

                case AutocompleteType.Coach:
                {
                    using (UaFootball_DBDataContext db = DBManager.GetDB())
                    {
                        IQueryable <AutoCompleteResponse> searchMatches = db.Coaches.Where(r => r.LastName.Contains(searchTerm)).Select(r => new AutoCompleteResponse {
                                id = r.CoachId, value = r.FirstName + " " + r.LastName
                            });
                        result.AddRange(searchMatches);
                        context.Response.Write(serializer.Serialize(result));
                    }
                    break;
                }

                case AutocompleteType.Player:
                {
                    using (UaFootball_DBDataContext db = DBManager.GetDB())
                    {
                        List <UaFDatabase.Player> searchMatches = db.Players.Where(r => r.Last_Name.StartsWith(searchTerm) || r.Display_Name.StartsWith(searchTerm) || r.Last_Name_Int.StartsWith(searchTerm)).ToList();
                        foreach (UaFDatabase.Player p in searchMatches)
                        {
                            AutoCompleteResponse r = new AutoCompleteResponse {
                                id = p.Player_Id
                            };
                            string formattedName = string.Format("{0} {1} '{2}'", p.First_Name, p.Last_Name, p.Display_Name);
                            formattedName = formattedName.Replace("''", "").Trim();
                            r.value       = formattedName;
                            result.Add(r);
                        }
                        context.Response.Write(serializer.Serialize(result));
                    }
                    break;
                }

                case AutocompleteType.SearchPlayerByShirtNum:
                {
                    string[] parameters = searchTerm.Split(';');
                    if (parameters.Length == 4)
                    {
                        int  teamId              = int.Parse(parameters[0]);
                        int  shirtNum            = int.Parse(parameters[1]);
                        bool isNationalTeamMatch = bool.Parse(parameters[2]);
                        bool searchBackward      = bool.Parse(parameters[3]);
                        using (UaFootball_DBDataContext db = DBManager.GetDB())
                        {
                            IQueryable <MatchLineup> dbLineups = null;

                            if (!isNationalTeamMatch)
                            {
                                dbLineups = (from lineup in db.MatchLineups
                                             where lineup.ShirtNumber == shirtNum && (lineup.IsHomeTeamPlayer && lineup.Match.HomeClub_Id == teamId || !lineup.IsHomeTeamPlayer && lineup.Match.AwayClub_Id == teamId)
                                                             //orderby lineup.Match.Date descending
                                             select lineup); //.FirstOrDefault();
                            }
                            else
                            {
                                dbLineups = (from lineup in db.MatchLineups
                                             where lineup.ShirtNumber == shirtNum && (lineup.IsHomeTeamPlayer && lineup.Match.HomeNationalTeam_Id == teamId || !lineup.IsHomeTeamPlayer && lineup.Match.AwayNationalTeam_Id == teamId)
                                                             //orderby lineup.Match.Date descending
                                             select lineup); //.FirstOrDefault();
                            }

                            if (searchBackward)
                            {
                                dbLineups = dbLineups.OrderBy(l => l.Match.Date);
                            }
                            else
                            {
                                dbLineups = dbLineups.OrderByDescending(l => l.Match.Date);
                            }

                            MatchLineup          lu   = dbLineups.FirstOrDefault();
                            AutoCompleteResponse resp = null;
                            if (lu != null)
                            {
                                UaFDatabase.Player p             = lu.Player;
                                string             formattedName = string.Empty;
                                if (!string.IsNullOrEmpty(p.Display_Name))
                                {
                                    formattedName = string.Format("{0} ({1} {2})", p.Display_Name.ToUpper(), p.First_Name, p.Last_Name);
                                }
                                else
                                {
                                    formattedName = string.Format("{0} {1}", p.First_Name, p.Last_Name);
                                }

                                if ((lu.Flags & Constants.DB.LineupFlags.Goalkeeper) > 0)
                                {
                                    formattedName = "*" + formattedName;
                                }
                                resp = new AutoCompleteResponse {
                                    id = p.Player_Id, value = formattedName
                                };
                            }
                            else
                            {
                                resp = new AutoCompleteResponse();
                            }
                            context.Response.Write(serializer.Serialize(resp));
                        }
                    }
                    break;
                }

                case AutocompleteType.MostRecentClubCoach:
                {
                    //term: [nc]Id
                    bool isNational           = searchTerm[0] == 'n';
                    int  teamId               = int.Parse(searchTerm.Substring(1));
                    AutoCompleteResponse resp = new AutoCompleteResponse();
                    using (UaFootball_DBDataContext db = DBManager.GetDB())
                    {
                        Match mostRecentMatch = (from match in db.Matches
                                                 where (match.HomeClub_Id == teamId || match.AwayClub_Id == teamId) && !isNational || (match.HomeNationalTeam_Id == teamId || match.AwayNationalTeam_Id == teamId) && isNational
                                                 orderby match.Date descending
                                                 select match).FirstOrDefault();
                        if (mostRecentMatch != null)
                        {
                            bool  isHomeTeam = mostRecentMatch.HomeClub_Id == teamId || mostRecentMatch.HomeNationalTeam_Id == teamId;
                            Coach teamCoach  = (from ml in db.MatchLineups
                                                where (ml.Match_Id == mostRecentMatch.Match_Id) && (ml.IsHomeTeamPlayer == isHomeTeam) && (ml.Coach_Id > 0)
                                                select ml.Coach).FirstOrDefault();
                            if (teamCoach != null)
                            {
                                resp.id    = teamCoach.CoachId;
                                resp.value = teamCoach.FirstName + " " + teamCoach.LastName;
                            }
                        }
                        context.Response.Write(serializer.Serialize(resp));
                    }
                    break;
                }

                case AutocompleteType.MostRecentStadium:
                {
                    using (UaFootball_DBDataContext db = DBManager.GetDB())
                    {
                        //term: [nc]Id
                        bool isNational           = searchTerm[0] == 'n';
                        int  teamId               = int.Parse(searchTerm.Substring(1));
                        AutoCompleteResponse resp = new AutoCompleteResponse();

                        Match mostRecentMatch = (from match in db.Matches
                                                 where (match.HomeClub_Id == teamId) && !isNational || (match.HomeNationalTeam_Id == teamId) && isNational
                                                 orderby match.Date descending
                                                 select match).FirstOrDefault();

                        if (mostRecentMatch != null)
                        {
                            resp.id    = mostRecentMatch.Stadium_Id;
                            resp.value = "";
                        }
                        context.Response.Write(serializer.Serialize(resp));
                    }
                    break;
                }

                case AutocompleteType.EventPlayer:
                    string response = String.Empty;
                    using (UaFootball_DBDataContext db = DBManager.GetDB())
                    {
                        string eventIdParam = context.Request["eventId"];
                        if (!string.IsNullOrEmpty(eventIdParam))
                        {
                            int eventId = int.Parse(eventIdParam);
                            UaFDatabase.MatchEvent me                 = db.MatchEvents.Single(m => m.MatchEvent_Id == eventId);
                            List <MatchLineup>     lineups            = db.MatchLineups.Where(ml => ml.Match_Id == me.Match_Id).ToList();
                            bool isHomeTeamPlayer                     = lineups.Single(l => l.Player_Id == me.Player1_Id).IsHomeTeamPlayer;
                            List <UaFDatabase.Player> sameTeamPlayers = db.Players.Where(p => lineups.Where(l => l.IsHomeTeamPlayer == isHomeTeamPlayer).Select(l => l.Player_Id).Contains(p.Player_Id)).ToList();
                            foreach (UaFDatabase.Player p in sameTeamPlayers)
                            {
                                if (p.Last_Name.ToLower().StartsWith(searchTerm.ToLower()) || (p.Display_Name ?? string.Empty).ToLower().StartsWith(searchTerm.ToLower()))
                                {
                                    AutoCompleteResponse r = new AutoCompleteResponse {
                                        id = p.Player_Id
                                    };
                                    string formattedName = string.Format("{0} {1} '{2}'", p.First_Name, p.Last_Name, p.Display_Name);
                                    formattedName = formattedName.Replace("''", "").Trim();
                                    r.value       = formattedName;
                                    result.Add(r);
                                }
                            }
                            response = serializer.Serialize(result);
                        }
                    }
                    context.Response.Write(response);
                    break;
                }
            }
            else
            {
                context.Response.Write(string.Empty);
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlMultimediaSubType.Items.Add(new ListItem(Constants.UI.MutlimediaSubTypes.ClubLogo, Constants.DB.MutlimediaSubTypes.ClubLogo));
                ddlMultimediaSubType.Items.Add(new ListItem(Constants.UI.MutlimediaSubTypes.NationalTeamLogo, Constants.DB.MutlimediaSubTypes.NationalTeamLogo));
                ddlMultimediaSubType.Items.Add(new ListItem(Constants.UI.MutlimediaSubTypes.PlayerLogo, Constants.DB.MutlimediaSubTypes.PlayerLogo));
                ddlMultimediaSubType.Items.Add(new ListItem(Constants.UI.MutlimediaSubTypes.MatchPhoto, Constants.DB.MutlimediaSubTypes.MatchPhoto));
                ddlMultimediaSubType.Items.Add(new ListItem(Constants.UI.MutlimediaSubTypes.MatchVideo, Constants.DB.MutlimediaSubTypes.MatchVideo));

                ddlMultimediaSubType.SelectedIndex = 3;
                ddlMultimediaSubType_SelectedIndexChanged(ddlMultimediaSubType, new EventArgs());

                cbl1.Items.Add(new ListItem(Constants.UI.MultimediaTags.BadQuality, Constants.DB.MultimediaTags.BadQuality.ToString()));
                cbl1.Items.Add(new ListItem(Constants.UI.MultimediaTags.AwayTeamPhoto, Constants.DB.MultimediaTags.AwayTeamPhoto.ToString()));
                cbl1.Items.Add(new ListItem(Constants.UI.MultimediaTags.HomeTeamPhoto, Constants.DB.MultimediaTags.HomeTeamPhoto.ToString()));



                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    int multimediaId = MMId;

                    if (multimediaId > 0)
                    {
                        btnDelete.Visible = true;

                        using (UaFootball_DBDataContext db = DBManager.GetDB())
                        {
                            UaFDatabase.Multimedia mm = db.Multimedias.SingleOrDefault(m => m.Multimedia_ID == multimediaId);
                            if (mm != null)
                            {
                                ddlMultimediaSubType.Enabled       = false;
                                afuUploader.Enabled                = false;
                                hfFileName.Value                   = mm.FileName;
                                ddlMultimediaSubType.SelectedValue = mm.MultimediaSubType_CD;
                                ddlMultimediaSubType_SelectedIndexChanged(ddlMultimediaSubType, new EventArgs());

                                List <MultimediaTag> tags = db.MultimediaTags.Where(m => m.Multimedia_ID == multimediaId).ToList();
                                if (tags.Count > 0)
                                {
                                    List <MultimediaTagDTO> tagsToBind = tags.Select(t => new MultimediaTagDTO {
                                        Club_ID = t.Club_ID, MatchEvent_ID = t.MatchEvent_ID, Match_ID = t.Match_ID, NationalTeam_ID = t.NationalTeam_ID, Player_ID = t.Player_ID, tmpId = t.MultimediaTag_ID, MultimediaTag_ID = t.MultimediaTag_ID
                                    }).ToList();
                                    foreach (MultimediaTagDTO mt in tagsToBind)
                                    {
                                        if (mt.Match_ID.HasValue)
                                        {
                                            mt.Type = _tagTypeGame;
                                            vwMatch match = db.vwMatches.SingleOrDefault(m => m.Match_ID == mt.Match_ID.Value);
                                            mt.Description = UIHelper.FormatMatch(match);
                                        }

                                        if (mt.Player_ID.HasValue)
                                        {
                                            mt.Type = _tagTypePlayer;
                                            PlayerDTO player = new PlayerDTOHelper().GetPlayer(mt.Player_ID.Value);
                                            mt.Description = UIHelper.FormatName(player);
                                        }

                                        if (mt.MatchEvent_ID.HasValue)
                                        {
                                            mt.Type = _tagTypeEvent;
                                            DataLoadOptions opt = new DataLoadOptions();
                                            opt.LoadWith <MatchEvent>(m => m.Player1);
                                            UaFDatabase.MatchEvent mEvent = db.MatchEvents.SingleOrDefault(m => m.MatchEvent_Id == mt.MatchEvent_ID.Value);

                                            mt.Description = string.Format("{0} мин - {1} - {2}", mEvent.Minute, UIHelper.EventCodeMap[mEvent.Event_Cd], FormatName(mEvent.Player.First_Name, mEvent.Player.Last_Name, mEvent.Player.Display_Name, mEvent.Player.Country_Id));
                                        }

                                        if (mt.Club_ID.HasValue)
                                        {
                                            mt.Type = _tagTypeClub;
                                            ClubDTO club = new ClubDTOHelper().GetFromDB(mt.Club_ID.Value);
                                            mt.Description = string.Format("{0} ({1})", club.Club_Name, club.City_Name);
                                        }

                                        if (mt.NationalTeam_ID.HasValue)
                                        {
                                            mt.Type        = _tagTypeNatTeam;
                                            mt.Description = "Украина";
                                        }
                                    }
                                    TagsCache.AddRange(tagsToBind);
                                    rptTags.DataSource = tagsToBind;
                                    rptTags.DataBind();
                                }

                                if (mm.Flags.HasValue)
                                {
                                    if (mm.Flags > 0)
                                    {
                                        foreach (ListItem li in cbl1.Items)
                                        {
                                            if ((long.Parse(li.Value) & mm.Flags.Value) > 0)
                                            {
                                                li.Selected = true;
                                            }
                                        }
                                    }
                                }

                                tbAuthor.Text      = mm.Author;
                                tbSource.Text      = mm.Source;
                                tbDescription.Text = mm.Description;
                                tbPhotoDate.Text   = FormatDate(mm.DateTaken);
                                if (mm.MultimediaType_CD == Constants.DB.MutlimediaTypes.Image)
                                {
                                    imgMultimedia.ImageUrl = PathHelper.GetWebPath(this, Constants.Paths.MutlimediaWebRoot, mm.FilePath, mm.FileName);
                                }
                            }
                        }
                    }
                }
            }
        }