public static MultimediaTagDTO FromDBObject(MultimediaTag mt) { return(new MultimediaTagDTO { Club_ID = mt.Club_ID, Match_ID = mt.Match_ID, MatchEvent_ID = mt.MatchEvent_ID, NationalTeam_ID = mt.NationalTeam_ID, Player_ID = mt.Player_ID }); }
public MatchDTO GetFromDB(int objectId) { using (UaFootball_DBDataContext db = DBManager.GetDB()) { var dbData = (from match in db.Matches where match.Match_Id == objectId select new { m = match, r = match.Referee, s = match.Stadium, cn = match.Stadium.City.City_Name, compName = match.Competition.Competition_Name, compStageName = match.CompetitionStage.CompetitionStage_Name }).Single(); MatchDTO ret = ConvertDBObjectToDTO(dbData.m); if (dbData.r != null) { ret.Referee = new RefereeDTOHelper().ConvertDBObjectToDTO(dbData.r); } ret.Stadium = new StadiumDTOHelper().ConvertDBObjectToDTO(dbData.s); ret.Stadium.City_Name = dbData.cn; ret.CompetitionName = dbData.compName; ret.CompetitionStageName = dbData.compStageName; if (ret.HomeNationalTeam_Id.HasValue) { ret.HomeTeamName = db.NationalTeams.Single(nt => nt.NationalTeam_Id == ret.HomeNationalTeam_Id).Country.Country_Name; ret.AwayTeamName = db.NationalTeams.Single(nt => nt.NationalTeam_Id == ret.AwayNationalTeam_Id).Country.Country_Name; MultimediaTag homeTeamLogoTag = db.MultimediaTags.Where(t => t.NationalTeam_ID == ret.HomeNationalTeam_Id && t.Multimedia.MultimediaSubType_CD == Constants.DB.MutlimediaSubTypes.NationalTeamLogo).OrderByDescending(m => m.Multimedia_ID).FirstOrDefault(); if (homeTeamLogoTag != null) { ret.HomeTeamLogo = MultimediaDTO.FromDBObject(homeTeamLogoTag.Multimedia); } MultimediaTag awayTeamLogoTag = db.MultimediaTags.Where(t => t.NationalTeam_ID == ret.AwayNationalTeam_Id && t.Multimedia.MultimediaSubType_CD == Constants.DB.MutlimediaSubTypes.NationalTeamLogo).OrderByDescending(m => m.Multimedia_ID).FirstOrDefault(); if (awayTeamLogoTag != null) { ret.AwayTeamLogo = MultimediaDTO.FromDBObject(awayTeamLogoTag.Multimedia); } } else { ret.HomeTeamName = db.Clubs.Single(c => c.Club_ID == ret.HomeClub_Id).Club_Name; ret.AwayTeamName = db.Clubs.Single(c => c.Club_ID == ret.AwayClub_Id).Club_Name; ret.HomeTeamLogo = db.MultimediaTags.Where(t => t.Club_ID == ret.HomeClub_Id && t.Multimedia.MultimediaSubType_CD == Constants.DB.MutlimediaSubTypes.ClubLogo).OrderByDescending(m => m.Multimedia_ID).Select(m => MultimediaDTO.FromDBObject(m.Multimedia)).FirstOrDefault(); ret.AwayTeamLogo = db.MultimediaTags.Where(t => t.Club_ID == ret.AwayClub_Id && t.Multimedia.MultimediaSubType_CD == Constants.DB.MutlimediaSubTypes.ClubLogo).OrderByDescending(m => m.Multimedia_ID).Select(m => MultimediaDTO.FromDBObject(m.Multimedia)).FirstOrDefault(); } IQueryable <MatchLineupDTO> lineup = from matchLineup in db.MatchLineups where matchLineup.Match_Id == objectId //&& matchLineup.Player_Id>0 orderby matchLineup.IsSubstitute, matchLineup.MatchLineup_Id select new MatchLineupDTO { IsHomeTeamPlayer = matchLineup.IsHomeTeamPlayer, IsSubstitute = matchLineup.IsSubstitute, Match_Id = matchLineup.Match_Id, Player_Id = matchLineup.Player_Id, MatchLineup_Id = matchLineup.MatchLineup_Id, Player_FirstName = matchLineup.Player.First_Name, Player_LastName = matchLineup.Player.Last_Name, Player_DisplayName = matchLineup.Player.Display_Name, Player_FirstName_Int = matchLineup.Player.First_Name_Int, Player_LastName_Int = matchLineup.Player.Last_Name_Int, Player_CountryId = matchLineup.Coach_Id.HasValue ? 0 : matchLineup.Player.Country_Id, ShirtNum = matchLineup.ShirtNumber, CoachId = matchLineup.Coach_Id, Coach_FirstName = matchLineup.Coach.FirstName, Coach_LastName = matchLineup.Coach.LastName, Flags = matchLineup.Flags ?? 0 }; ret.Lineup.AddRange(lineup.AsEnumerable()); IQueryable <MatchEventDTO> events = from matchEvent in db.MatchEvents where matchEvent.Match_Id == objectId select new MatchEventDTO { Event_Cd = matchEvent.Event_Cd, EventFlags = matchEvent.EventFlags, Match_Id = objectId, MatchEvent_Id = matchEvent.MatchEvent_Id, Minute = matchEvent.Minute, Player1 = new PlayerDTO { First_Name = matchEvent.Player.First_Name, Last_Name = matchEvent.Player.Last_Name, Display_Name = matchEvent.Player.Display_Name, Country_Id = matchEvent.Player.Player_Id > 0 ? matchEvent.Player.Country_Id : 0 }, Player1_Id = matchEvent.Player1_Id, //Player1_FName = matchEvent.Player.First_Name, //Player1_SName = matchEvent.Player.Last_Name, //Player1_DName = matchEvent.Player.Display_Name, //Player2_FName = matchEvent.Player1.First_Name, //Player2_SName = matchEvent.Player1.Last_Name, //Player2_DName = matchEvent.Player1.Display_Name, Player2_Id = matchEvent.Player2_Id, Player2 = new PlayerDTO { First_Name = matchEvent.Player1.First_Name, Last_Name = matchEvent.Player1.Last_Name, Display_Name = matchEvent.Player1.Display_Name, Country_Id = matchEvent.Player1.Player_Id > 0 ? matchEvent.Player1.Country_Id : 0 } }; ret.Events.AddRange(events.AsEnumerable()); IQueryable <MultimediaDTO> multimedia = (from m in db.Multimedias join mt in db.MultimediaTags on m.Multimedia_ID equals mt.Multimedia_ID where mt.Match_ID == objectId select m).Distinct().Select(m => new MultimediaDTO { Multimedia_ID = m.Multimedia_ID, MultimediaType_CD = m.MultimediaType_CD }); ret.Multimedia = new List <MultimediaDTO>(); ret.Multimedia.AddRange(multimedia); IQueryable <MatchNoteDTO> notes = from note in db.MatchNotes where note.Match_Id == objectId select new MatchNoteDTO { Code = note.Code.Trim(), Text = note.Text, MatchNote_Id = note.MatchNote_Id }; ret.Notes.AddRange(notes); for (int i = 0; i < ret.Notes.Count; i++) { MatchNoteDTO note = ret.Notes[i]; note.CodeDescription = Constants.MatchNoteSetups.Single(s => s.Code == note.Code).Description; note.RowIndex = i; } return(ret); } }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { bool isValid = ValidateTags(); if (isValid) { if (string.IsNullOrEmpty(Request["id"])) { //Get mmedia information from UI UaFDatabase.Multimedia newMM = new UaFDatabase.Multimedia(); newMM.MultimediaType_CD = isImage(UploadedFileName) ? Constants.DB.MutlimediaTypes.Image : Constants.DB.MutlimediaTypes.Video; newMM.MultimediaSubType_CD = ddlMultimediaSubType.SelectedValue; newMM.MultimediaTags = new EntitySet <MultimediaTag>(); newMM.Author = tbAuthor.Text; newMM.Source = tbSource.Text; newMM.Description = tbDescription.Text; newMM.Flags = 0; foreach (ListItem li in cbl1.Items) { if (li.Selected) { newMM.Flags = newMM.Flags | long.Parse(li.Value); } } foreach (MultimediaTagDTO mmTag in TagsCache) { MultimediaTag mt = new MultimediaTag { Club_ID = mmTag.Club_ID, Match_ID = mmTag.Match_ID, NationalTeam_ID = mmTag.NationalTeam_ID, Player_ID = mmTag.Player_ID, MatchEvent_ID = mmTag.MatchEvent_ID }; newMM.MultimediaTags.Add(mt); } newMM.FilePath = PathHelper.GetMultimediaRelativePath(newMM); newMM.FileName = UploadedFileName; newMM.DateAdded = DateTime.Now; newMM.DateUpdated = DateTime.Now; newMM.DateTaken = getDateTaken(); //1. Save file to permanent location if (newMM.FilePath.Length > 0) { string destinationDirectoryPath = PathHelper.GetFileSystemPath(Constants.Paths.MultimediaStorageRoot, newMM.FilePath, ""); if (!Directory.Exists(destinationDirectoryPath)) { Directory.CreateDirectory(destinationDirectoryPath); } string uploadedFilePath = PathHelper.GetFileSystemPath(Constants.Paths.MultimediaStorageRoot, _tmpUploadPath, UploadedFileName); string destinationFilePath = PathHelper.GetFileSystemPath(Constants.Paths.MultimediaStorageRoot, newMM.FilePath, newMM.FileName); if (!File.Exists(destinationFilePath)) { File.Copy(uploadedFilePath, destinationFilePath); //Create thumbnail for image if (ddlMultimediaSubType.SelectedValue == Constants.DB.MutlimediaSubTypes.MatchPhoto || ddlMultimediaSubType.SelectedValue == Constants.DB.MutlimediaSubTypes.NationalTeamLogo || ddlMultimediaSubType.SelectedValue == Constants.DB.MutlimediaSubTypes.ClubLogo || ddlMultimediaSubType.SelectedValue == Constants.DB.MutlimediaSubTypes.PlayerLogo) { string thumbnailDirectoryPath = PathHelper.GetFileSystemPath(destinationDirectoryPath, "thumb", ""); if (!Directory.Exists(thumbnailDirectoryPath)) { Directory.CreateDirectory(thumbnailDirectoryPath); } string destinationThumbFilePath = PathHelper.GetFileSystemPath(thumbnailDirectoryPath, "", UploadedFileName); int thumbnailMaxHeight = 150; switch (ddlMultimediaSubType.SelectedValue) { case Constants.DB.MutlimediaSubTypes.MatchPhoto: default: { thumbnailMaxHeight = 150; break; } case Constants.DB.MutlimediaSubTypes.NationalTeamLogo: case Constants.DB.MutlimediaSubTypes.ClubLogo: { thumbnailMaxHeight = 150; break; } case Constants.DB.MutlimediaSubTypes.PlayerLogo: { thumbnailMaxHeight = 300; break; } } if (ddlMultimediaSubType.SelectedValue == Constants.DB.MutlimediaSubTypes.MatchPhoto) { thumbnailMaxHeight = 100; } isValid = new BitmapHelper().ResizeImage(uploadedFilePath, destinationThumbFilePath, thumbnailMaxHeight, null); } if (isValid) { lblError.Text = "File " + UploadedFileName + " successfully saved"; tbDescription.Text = ""; File.Delete(uploadedFilePath); } else { isValid = false; lblError.Text = "Error creating thumbnail"; } } else { isValid = false; lblError.Text = "File already exists"; } } //2. Save tags to DB if (isValid) { using (UaFootball_DBDataContext db = DBManager.GetDB()) { db.Multimedias.InsertOnSubmit(newMM); db.SubmitChanges(); } TagsCache.RemoveAll(mt => mt.Type != _tagTypeGame); rptTags.DataSource = TagsCache; rptTags.DataBind(); foreach (ListItem li in cbl1.Items) { li.Selected = false; } } } else //update mm { int multimediaId = 0; if (int.TryParse(Request["id"], out multimediaId)) { using (UaFootball_DBDataContext db = DBManager.GetDB()) { UaFDatabase.Multimedia mm = db.Multimedias.SingleOrDefault(m => m.Multimedia_ID == multimediaId); if (mm != null) { mm.Author = tbAuthor.Text; mm.Description = tbDescription.Text; mm.Source = tbSource.Text; mm.MultimediaTags.Clear(); db.MultimediaTags.DeleteAllOnSubmit(db.MultimediaTags.Where(m => m.Multimedia_ID == multimediaId)); foreach (MultimediaTagDTO mmTag in TagsCache) { MultimediaTag mt = new MultimediaTag { Club_ID = mmTag.Club_ID, Match_ID = mmTag.Match_ID, NationalTeam_ID = mmTag.NationalTeam_ID, Player_ID = mmTag.Player_ID, MatchEvent_ID = mmTag.MatchEvent_ID }; mm.MultimediaTags.Add(mt); } mm.Flags = 0; foreach (ListItem li in cbl1.Items) { if (li.Selected) { mm.Flags = mm.Flags | long.Parse(li.Value); } } mm.DateUpdated = DateTime.Now; mm.DateTaken = getDateTaken(); db.SubmitChanges(); } } } } } else { lblError.Text = "Ошибка в тегах"; } } }