Esempio n. 1
0
        void CreateUser(NHibernate.ISession s, string Name, string Pass, string RoleName)
        {
            if (!AConst.Roles.Contains(RoleName))
            {
                throw new Exception("Unkown role" + RoleName);
            }
            var newUserRole = (from role in s.Query <GlRole>() where role.Name == RoleName select role).ToList().FirstOrDefault();

            if (newUserRole == null)
            {
                throw new Exception("Unable to find role " + RoleName + " in databases");
            }
            s.SaveOrUpdate(new GlUser()
            {
                Name = Name, Password = Pass
            });
            var createdUser = (from item in s.Query <GlUser>() where item.Name == Name select item).ToList().FirstOrDefault();

            if (createdUser == null)
            {
                throw new Exception("Unable to create user " + Name + " with role " + RoleName);
            }
            createdUser.UserRoles = new List <GlUserRole>()
            {
                new GlUserRole()
                {
                    CurrentUser = createdUser, CurrentRole = newUserRole
                }
            };
            s.SaveOrUpdate(createdUser);
        }
Esempio n. 2
0
        public bool removeIstruttore(Istruttore i)
        {
            // elimina i collegamenti coi corsi che tiene
            Corso[] corsi_che_tiene = i.Corsi.ToArray();
            foreach (Corso c in corsi_che_tiene)
            {
                c.Istruttori.Remove(i);
                i.Corsi.Remove(c);
            }

            istruttori.Remove(i);

            using (NHibernate.ISession session = HibernateHelper.Open())
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    try
                    {
                        foreach (Corso c in corsi_che_tiene)
                        {
                            session.SaveOrUpdate(c);
                        }
                        session.SaveOrUpdate(i);
                        session.Delete(i);

                        transaction.Commit();
                        return(true);
                    }
                    catch (Exception exc)
                    {
                        Log.Instance.WriteLine(Log.LogLevel.Error, "instance::removeIstruttore(" + (i != null ? i.ID.ToString() : "null") + "):" + exc.Message);
                        return(false);
                    }
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the alias.
        /// </summary>
        /// <param name="evt">The evt.</param>
        /// <param name="name">The name.</param>
        /// <param name="message">The message.</param>
        private void SaveAlias(Event evt, string name, Message message)
        {
            bool hasTagInDictionary = _aliasLookup.ContainsKey(message.From);
            var  alias = new Alias {
                Event = evt, Name = name, Number = message.From
            };

            //get Instance of existing hashtag
            if (hasTagInDictionary)
            {
                alias      = _aliasLookup[message.From];
                alias.Name = name;
            }

            //save hashtage
            using (var trans = _session.BeginTransaction())
            {
                _session.SaveOrUpdate(alias);
                trans.Commit();
            }

            //update hashtag collection
            if (!hasTagInDictionary)
            {
                _aliasLookup.Add(message.From, alias);
            }
        }
Esempio n. 4
0
        private void SaveAndRetrieve(NHibernate.ISession session, TEntity item)
        {
            using (var transaction = session.BeginTransaction())
            {
                session.SaveOrUpdate(item);

                //session.Flush();
                transaction.Commit();
            }
        }
Esempio n. 5
0
        private void CreateAndSaveArt(string pArtist, string pAlbum, string pPath, NHibernate.ISession pDataSession, ArtType pType)
        {
            var key = pArtist + "|" + pAlbum;

            var art = new Art();

            art.ArtType = (int)pType;
            art.Key     = key;
            art.Path    = pPath;
            try
            {
                pDataSession.SaveOrUpdate(art);
            }
            catch { } // ignore.
        }
Esempio n. 6
0
 public static bool saveIscrizione(Iscrizione p)
 {
     using (NHibernate.ISession session = HibernateHelper.Open())
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
             try
             {
                 session.SaveOrUpdate(p);
                 transaction.Commit();
                 return(true);
             }
             catch (Exception exc)
             {
                 Log.Instance.WriteLine(Log.LogLevel.Error, "saveIscrizione(" + (p != null ? p.ID.ToString() : "null") + "):" + exc.Message);
                 return(false);
             }
 }
Esempio n. 7
0
        public static List <Match> ToDb(this NHibernate.ISession session, IList <Entity.NHibernate.EventParent> competitions, DateTime dt)
        {
            PrepareForDb(ref competitions);

            List <Match> matches = new List <Match>();
            // save both stores, this saves everything else via cascading
            // save both stores, this saves everything else via cascading
            var gcomps = competitions.GroupBy(_ => _.Key);

            // populate the database


            foreach (var competition in gcomps)
            {
                using (var transaction = session.BeginTransaction())
                {
                    var fcompetition = competition.First();


                    var gmatches = gcomps.SelectMany(_ => _.SelectMany(c => c.Matches.Where(m => new DateTime(m.Start) < dt))).ToList();
                    //foreach (var match in gmatches)
                    //    match.EventParent = fcompetition;

                    if (session.QueryOver <Entity.NHibernate.EventParent>().RowCount() == 0 || session.QueryOver <Entity.NHibernate.EventParent>().Where(x => x.Key == competition.Key).RowCount() == 0)
                    {
                        session.SaveOrUpdate(competition.First());
                    }

                    //var gmatches = gcomps.SelectMany(_ => _.SelectMany(c => c.Matches));

                    //foreach (var m in gmatches)
                    //    m.EventParent = fcompetition;
                    var gml = gmatches.ToList();
                    matches.AddRange(gml);
                    session.ToDb(gml);


                    transaction.Commit();
                }
            }

            return(matches);
        }
Esempio n. 8
0
 public bool UpdateNewsLatterSetting(NewsLetterSetting _NewsLetterSetting)
 {
     try
     {
         using (NHibernate.ISession session = SessionFactory.GetNewSession())
         {
             NewsLetterSetting objNewsLetterSetting = new NewsLetterSetting();
             try
             {
                 objNewsLetterSetting = session.Query <NewsLetterSetting>().Where(t => t.userId == _NewsLetterSetting.userId).SingleOrDefault();
             }
             catch (Exception ex)
             {
                 objNewsLetterSetting = null;
             }
             using (NHibernate.ITransaction transaction = session.BeginTransaction())
             {
                 if (objNewsLetterSetting == null)
                 {
                     session.Save(_NewsLetterSetting);
                 }
                 else
                 {
                     objNewsLetterSetting.groupReport_Daily = _NewsLetterSetting.groupReport_Daily;
                     objNewsLetterSetting.groupReport_7     = _NewsLetterSetting.groupReport_7;
                     objNewsLetterSetting.groupReport_15    = _NewsLetterSetting.groupReport_15;
                     objNewsLetterSetting.groupReport_30    = _NewsLetterSetting.groupReport_30;
                     objNewsLetterSetting.groupReport_60    = _NewsLetterSetting.groupReport_60;
                     objNewsLetterSetting.groupReport_90    = _NewsLetterSetting.groupReport_90;
                     objNewsLetterSetting.others            = _NewsLetterSetting.others;
                     session.SaveOrUpdate(objNewsLetterSetting);
                 }
                 transaction.Commit();
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Esempio n. 9
0
        public static bool saveIscrizioni(List <Iscrizione> p)
        {
            using (NHibernate.ISession session = HibernateHelper.Open())
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    try
                    {
                        foreach (Iscrizione i in p)
                        {
                            session.SaveOrUpdate(i);
                        }

                        transaction.Commit();
                        return(true);
                    }
                    catch (Exception exc)
                    {
                        Log.Instance.WriteLine(Log.LogLevel.Error, "saveIscrizioni::" + exc.Message);
                        return(false);
                    }
        }
Esempio n. 10
0
        public static bool savePersona(Persona p)
        {
            using (NHibernate.ISession session = HibernateHelper.Open())
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    try
                    {
                        session.SaveOrUpdate(p);
                        transaction.Commit();
                        return(true);
                    }
                    catch (Exception exc)
                    {
                        Log.Instance.WriteLine(Log.LogLevel.Error, "savePersona(" +
                                               (p != null ?
                                                p.Nome ?? string.Empty + " " + p.Cognome ?? string.Empty
                                : "null") + "):" + exc.Message);

                        return(false);
                    }
        }
Esempio n. 11
0
        public static bool savePersona(Persona[] p)
        {
            using (NHibernate.ISession session = HibernateHelper.Open())
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    try
                    {
                        foreach (Persona pers in p)
                        {
                            session.SaveOrUpdate(pers);
                        }

                        transaction.Commit();
                        return(true);
                    }
                    catch (Exception exc)
                    {
                        Log.Instance.WriteLine(Log.LogLevel.Error, "savePersone:" + exc.Message);
                        return(false);
                    }
        }
Esempio n. 12
0
        public static bool ToDb(this NHibernate.ISession session, IList <Entity.NHibernate.EventParent> competitions)
        {
            // save both stores, this saves everything else via cascading
            var gcomps = competitions.GroupBy(_ => _.Key);

            foreach (var competition in gcomps)
            {
                var fcompetition  = competition.First();
                var competitionId = fcompetition.Id;
                if (session.QueryOver <Entity.NHibernate.EventParent>().RowCount() == 0 || session.QueryOver <Entity.NHibernate.EventParent>().Where(x => x.Key == competition.Key).RowCount() == 0)
                {
                    session.SaveOrUpdate(competition.First());
                }

                var gmatches = gcomps.SelectMany(_ => _.SelectMany(c => c.Matches));

                session.ToDb(gmatches.ToList());
            }

            return(true);
        }
Esempio n. 13
0
        public static bool ToDb(this NHibernate.ISession session, IList <Match> matches)
        {
            // save both stores, this saves everything else via cascading

            var gmatches = matches.GroupBy(_ => _.Id);

            foreach (var match in gmatches)
            {
                var fmatch  = match.First();
                var matchId = fmatch.Id;

                //foreach (var market in gmatches.SelectMany(_ => _.SelectMany(xc => xc.Markets)))
                //{
                //    market.Match = fmatch;

                //}

                //if (session.QueryOver<Match>().RowCount() == 0 || session.QueryOver<Match>().Where(x => x.Id == match.Key).RowCount() == 0)


                session.SaveOrUpdate(fmatch);

                var gmarkets = match.SelectMany(_ => _.Markets.GroupBy(_j => _j.Id));

                foreach (var market in gmarkets)
                {
                    var fmarket = market.First();


                    //if (session.QueryOver<Market>().RowCount() == 0 || session.QueryOver<Market>().Where(x => x.Id == market.Key).RowCount() == 0)
                    //{

                    //fmarket.Match = fmatch;
                    session.SaveOrUpdate(fmarket);

                    //}

                    var gcontracts = market.SelectMany(_ => _.Contracts.GroupBy(_j => _j.Id));

                    foreach (var contract in gcontracts)
                    {
                        var fcontract = contract.First();


                        //if (session.QueryOver<Contract>().RowCount() == 0 || session.QueryOver<Contract>().Where(x => x.Id == contract.Key).RowCount() == 0)
                        //{
                        //fcontract.Market = fmarket;
                        session.SaveOrUpdate(fcontract);

                        //}
                        foreach (var price in contract.SelectMany(x => x.Prices))
                        {
                            // var id = session.QueryOver<Contract>().RowCount();
                            //if (session.QueryOver<Contract>().RowCount() == 0 || session.QueryOver<Contract>().Where(x => x.Id == market.Key).RowCount() == 0)
                            //{

                            //price.Id = i + 1;
                            //price.Contract = fcontract;
                            session.SaveOrUpdate(price);
                            //i++;
                            // }
                        }
                    }

                    //var gteams= match.SelectMany(_ => _.Teams.GroupBy(_j => _j.Key));

                    //foreach (var matchteam in gteams)
                    //{
                    //    var fmt = matchteam.First();
                    //    fmt.Id = i;
                    //    session.Save(matchteam);
                    //    i++;
                    //}
                }
            }

            return(true);
        }