Пример #1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int multimediaId = MMId;

            using (UaFootball_DBDataContext db = DBManager.GetDB())
            {
                if (multimediaId > 0)
                {
                    UaFDatabase.Multimedia mm = db.Multimedias.SingleOrDefault(m => m.Multimedia_ID == multimediaId);
                    if (mm != null)
                    {
                        db.MultimediaTags.DeleteAllOnSubmit(db.MultimediaTags.Where(m => m.Multimedia_ID == multimediaId));
                        db.Multimedias.DeleteOnSubmit(mm);

                        string filePath = PathHelper.GetFileSystemPath(Constants.Paths.MultimediaStorageRoot, mm.FilePath, mm.FileName);
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }

                        db.SubmitChanges();
                    }
                }
            }
        }
Пример #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);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        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 = "Ошибка в тегах";
                }
            }
        }