Esempio n. 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();
                    }
                }
            }
        }
Esempio n. 2
0
        public int SaveToDB(CountryDTO dtoObj)
        {
            Country dbObj = new Country();

            using (UaFootball_DBDataContext db = DBManager.GetDB())
            {
                if (dtoObj.Country_ID > 0)
                {
                    dbObj = db.Countries.Single(cc => cc.Country_ID == dtoObj.Country_ID);
                }
                else
                {
                    db.Countries.InsertOnSubmit(dbObj);
                    NationalTeam newNationalTeam = new NationalTeam {
                        Country = dbObj, NationalTeamType_Cd = Constants.DB.NationalTeamTypeCd_National
                    };
                    NationalTeam newNationalU21Team = new NationalTeam {
                        Country = dbObj, NationalTeamType_Cd = Constants.DB.NationalTeamTypeCd_U21
                    };
                    db.NationalTeams.InsertOnSubmit(newNationalTeam);
                    db.NationalTeams.InsertOnSubmit(newNationalU21Team);
                }

                CopyDTOToDbObject(dtoObj, dbObj);

                db.SubmitChanges();

                return(dbObj.Country_ID);
            }
        }
Esempio n. 3
0
        public int SaveToDB(ClubDTO dtoObj)
        {
            Club dbObj = new Club();

            using (UaFootball_DBDataContext db = DBManager.GetDB())
            {
                if (dtoObj.Club_ID > 0)
                {
                    dbObj = db.Clubs.Single(cc => cc.Club_ID == dtoObj.Club_ID);
                }
                else
                {
                    db.Clubs.InsertOnSubmit(dbObj);
                }

                CopyDTOToDbObject(dtoObj, dbObj);


                IEnumerable <MultimediaTag> mTagsToDel = db.MultimediaTags.Where(t => t.Club_ID == dtoObj.Club_ID && t.Multimedia.MultimediaSubType_CD == Constants.DB.MutlimediaSubTypes.ClubLogo);
                db.MultimediaTags.DeleteAllOnSubmit(mTagsToDel);


                db.SubmitChanges();

                return(dbObj.Club_ID);
            }
        }
Esempio n. 4
0
        public int SaveToDB(PlayerDTO dtoObj)
        {
            Player dbObj = new Player();

            using (UaFootball_DBDataContext db = DBManager.GetDB())
            {
                if (dtoObj.Player_Id > 0)
                {
                    dbObj = db.Players.Single(cc => cc.Player_Id == dtoObj.Player_Id);
                }
                else
                {
                    db.Players.InsertOnSubmit(dbObj);
                }

                CopyDTOToDbObject(dtoObj, dbObj);

                /*IEnumerable<MultimediaTag> mTagsToDel = db.MultimediaTags.Where(t => t.Player_ID == dtoObj.Player_Id && t.Multimedia.MultimediaSubType_CD == Constants.DB.MutlimediaSubTypes.PlayerLogo);
                 * db.MultimediaTags.DeleteAllOnSubmit(mTagsToDel);
                 *
                 * foreach (MultimediaDTO multimedia in dtoObj.Multimedia)
                 * {
                 *  Multimedia dbMultimedia = new Multimedia();
                 *  multimedia.CopyDTOToDbObject(dbMultimedia);
                 *
                 *  if (!multimedia.IsUploaded)
                 *  {
                 *      string mmRelativePath = PathHelper.GetMultimediaRelativePath(dbMultimedia);
                 *      string dropBoxFilePath = PathHelper.GetFileSystemPath(Constants.Paths.DropBoxPath, mmRelativePath, multimedia.FileName);
                 *
                 *      FileInfo fi = new FileInfo(dropBoxFilePath);
                 *      if (fi.Exists)
                 *      {
                 *          DateTime Now = DateTime.Now;
                 *          string newFileName = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}", Now.Year, Now.Month, Now.Day, Now.Hour, Now.Minute, Now.Second, Now.Millisecond, fi.Extension);
                 *          string newFilePath = PathHelper.GetFileSystemPath(Constants.Paths.MultimediaStorageRoot, mmRelativePath, multimedia.FileName);
                 *
                 *          File.Copy(dropBoxFilePath, newFilePath);
                 *
                 *          dbMultimedia.FilePath = "";
                 *          dbMultimedia.FileName = newFileName;
                 *      }
                 *  }
                 *
                 *  db.Multimedias.InsertOnSubmit(dbMultimedia);
                 *
                 *  MultimediaTag newTag = new MultimediaTag();
                 *  newTag.Multimedia = dbMultimedia;
                 *  newTag.Player = dbObj;
                 *  db.MultimediaTags.InsertOnSubmit(newTag);
                 *
                 * }*/

                db.SubmitChanges();

                return(dbObj.Player_Id);
            }
        }
Esempio n. 5
0
 private void DeleteNote(int noteId)
 {
     using (UaFootball_DBDataContext db = DBManager.GetDB())
     {
         MatchNote noteToDelete = db.MatchNotes.SingleOrDefault(mn => mn.MatchNote_Id == noteId);
         if (noteToDelete != null)
         {
             db.MatchNotes.DeleteOnSubmit(noteToDelete);
         }
         db.SubmitChanges();
     }
 }
Esempio n. 6
0
        public int SaveToDB(CityDTO dtoObj)
        {
            City dbObj = new City();

            using (UaFootball_DBDataContext db = DBManager.GetDB())
            {
                if (dtoObj.City_ID > 0)
                {
                    dbObj = db.Cities.Single(cc => cc.City_ID == dtoObj.City_ID);
                }
                else
                {
                    db.Cities.InsertOnSubmit(dbObj);
                }

                CopyDTOToDbObject(dtoObj, dbObj);

                db.SubmitChanges();

                return(dbObj.City_ID);
            }
        }
Esempio n. 7
0
        //public RefereeDTO GetFullFromDB(int objectId)
        //{
        //    using (UaFootball_DBDataContext db = DBManager.GetDB())
        //    {
        //        DataLoadOptions options = new DataLoadOptions();
        //        options.LoadWith<Match>(m => m.MatchEvents);
        //        db.LoadOptions = options;

        //        var dbData = (from Referee in db.Referees
        //                      where Referee.Referee_Id == objectId
        //                      select new { p = Referee, c = Referee.Country.Country_Name }).Single();
        //        RefereeDTO ret = ConvertDBObjectToDTO(dbData.p);
        //        ret.CountryName = dbData.c;

        //        //var matchData =


        //        var matchesData = from m in db.Matches where m.Referee_Id == objectId select m;
        //        MatchDTOHelper mDTOHelper = new MatchDTOHelper();
        //        MatchEventDTO meDTO = new MatchEventDTO();
        //        foreach (Match dbMatch in matchesData)
        //        {
        //            MatchDTO mDTO = mDTOHelper.ConvertDBObjectToDTO(dbMatch);
        //            foreach (MatchEvent me in dbMatch.MatchEvents)
        //            {
        //                mDTO.Events.Add(meDTO.ConvertDBObjectToDTO(me));
        //            }
        //            ret.Matches.Add(mDTO);
        //        }
        //        return (ret);
        //    }
        //}

        public int SaveToDB(RefereeDTO dtoObj)
        {
            Referee dbObj = new Referee();

            using (UaFootball_DBDataContext db = DBManager.GetDB())
            {
                if (dtoObj.Referee_Id > 0)
                {
                    dbObj = db.Referees.Single(cc => cc.Referee_Id == dtoObj.Referee_Id);
                }
                else
                {
                    db.Referees.InsertOnSubmit(dbObj);
                }

                CopyDTOToDbObject(dtoObj, dbObj);

                db.SubmitChanges();

                return(dbObj.Referee_Id);
            }
        }
Esempio n. 8
0
        //public CoachDTO GetFullFromDB(int objectId)
        //{
        //    using (UaFootball_DBDataContext db = DBManager.GetDB())
        //    {
        //        DataLoadOptions options = new DataLoadOptions();
        //        options.LoadWith<Match>(m => m.MatchEvents);
        //        db.LoadOptions = options;

        //        var dbData = (from Coach in db.Coachs
        //                      where Coach.Coach_Id == objectId
        //                      select new { p = Coach, c = Coach.Country.Country_Name }).Single();
        //        CoachDTO ret = ConvertDBObjectToDTO(dbData.p);
        //        ret.CountryName = dbData.c;

        //        //var matchData =


        //        var matchesData = from m in db.Matches where m.Coach_Id == objectId select m;
        //        MatchDTOHelper mDTOHelper = new MatchDTOHelper();
        //        MatchEventDTO meDTO = new MatchEventDTO();
        //        foreach (Match dbMatch in matchesData)
        //        {
        //            MatchDTO mDTO = mDTOHelper.ConvertDBObjectToDTO(dbMatch);
        //            foreach (MatchEvent me in dbMatch.MatchEvents)
        //            {
        //                mDTO.Events.Add(meDTO.ConvertDBObjectToDTO(me));
        //            }
        //            ret.Matches.Add(mDTO);
        //        }
        //        return (ret);
        //    }
        //}

        public int SaveToDB(CoachDTO dtoObj)
        {
            Coach dbObj = new Coach();

            dtoObj.ModifiedDate = DateTime.Now;
            using (UaFootball_DBDataContext db = DBManager.GetDB())
            {
                if (dtoObj.CoachId > 0)
                {
                    dbObj = db.Coaches.Single(cc => cc.CoachId == dtoObj.CoachId);
                }
                else
                {
                    db.Coaches.InsertOnSubmit(dbObj);
                }

                CopyDTOToDbObject(dtoObj, dbObj);

                db.SubmitChanges();

                return(dbObj.CoachId);
            }
        }
Esempio n. 9
0
        public int SaveToDB(StadiumDTO dtoObj)
        {
            Stadium dbObj = new Stadium();

            using (UaFootball_DBDataContext db = DBManager.GetDB())
            {
                if (dtoObj.Stadium_ID > 0)
                {
                    dbObj = db.Stadiums.Single(cc => cc.Stadium_Id == dtoObj.Stadium_ID);
                }
                else
                {
                    dbObj.DateAdded = DateTime.Now;
                    db.Stadiums.InsertOnSubmit(dbObj);
                }

                CopyDTOToDbObject(dtoObj, dbObj);

                db.SubmitChanges();

                return(dbObj.Stadium_Id);
            }
        }
Esempio n. 10
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 = "Ошибка в тегах";
                }
            }
        }
Esempio n. 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string normalSymbols         = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' -ecaisocuocuenaraazoSlACsOyeoeinsuELDsOIaZsezttCCOd";
            string extraSymbols          = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' -éćáíšöčúóçüëñãřäăžôŠłÁČşÖýěøèïńßůÉŁĎśÓÍâŽșęźţțĆÇØđ";
            Dictionary <char, int> stats = new Dictionary <char, int>();

            using (UaFootball_DBDataContext db = DBManager.GetDB())
            {
                List <UaFDatabase.Player> pls = db.Players.ToList();

                //for (int i = 0; i < pls.Count; i++)
                //{
                //    var p = pls[i];
                //    string fullName = (p.First_Name_Int.Trim() + ' ' + p.Last_Name_Int.Trim());

                //    for (int j = 0; j < fullName.Length; j++)
                //    {
                //        if (!extraSymbols.Contains(fullName[j]))
                //        {
                //            if (!stats.ContainsKey(fullName[j]))
                //            {
                //                stats.Add(fullName[j], 1);
                //            }
                //            else
                //            {
                //                stats[fullName[j]]++;
                //            }
                //        }
                //    }
                //}

                Dictionary <char, char> normalizationDictionary = new Dictionary <char, char>();
                for (int j = 0; j < normalSymbols.Length; j++)
                {
                    normalizationDictionary.Add(extraSymbols[j], normalSymbols[j]);
                }

                for (int i = 0; i < pls.Count; i++)
                {
                    var    p        = pls[i];
                    string fullName = (p.First_Name_Int.Trim() + ' ' + p.Last_Name_Int.Trim());

                    string normalizedName = fullName;
                    for (int j = 0; j < fullName.Length; j++)
                    {
                        normalizedName = normalizedName.Replace(fullName[j], normalizationDictionary[fullName[j]]);
                    }

                    if (fullName.Length > 1)
                    {
                        //db.Players.Attach(p);
                        p.NameSearchString = normalizedName;
                    }
                }

                db.SubmitChanges();
            }

            lvSymb.DataSource = stats.OrderBy(kv => kv.Value);
            lvSymb.DataBind();

            lbl.Text = string.Join("", stats.OrderByDescending(kv => kv.Value).Select(s => s.Key.ToString()).ToArray());
        }