Esempio n. 1
0
        public static int Update(Person p, DatabaseT pDb = null)
        {
            DatabaseT db = new DatabaseT();

            db.Connect();
            db.BeginTransaction();
            Person prv = SelectOne(p.Id);

            if (p.Role != "Coach" && prv.Role == "Coach")
            {
                Team ot = TeamTable.SelectOne(p.Team_Id.Id);
                ot.Person_Id = null;
                TeamTable.Update(ot);
            }


            OracleCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, p);

            int ret = db.ExecuteNonQuery2(command);

            db.EndTransaction();
            db.Close();
            return(ret);
        }
Esempio n. 2
0
        public static int UpdateManager(Organisation o, int pID, bool is_manager, DatabaseT pDb = null)
        {
            DatabaseT db = new DatabaseT();

            db.Connect();

            db.BeginTransaction();
            if (SelectOne(o.Id) == null)
            {
                Console.WriteLine("Organizace nenalezena");
                db.Rollback();
                return(-1);
            }
            if (PersonTable.SelectOne(pID) == null)
            {
                Console.WriteLine("Osoba nenalezena");
                db.Rollback();
                return(-1);
            }

            if (o.Person_Id.Id == pID)
            {
                Console.WriteLine("Osoba j*z je kontaktni osobou organizace");
                db.Rollback();
                return(-1);
            }

            try
            {
                Person p = new Person();
                p = PersonTable.SelectOne(pID);

                if (is_manager)
                {
                    p.Role = "Manager";
                }
                else
                {
                    p.Role = null;
                }
                PersonTable.Update(p);

                o.Person_Id.Id = pID;
                Update(o);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                db.Rollback();
                return(-1);
            }


            OracleCommand command = db.CreateCommand(SQL_UPDATE_MAN);

            PrepareCommand(command, o);
            int ret = db.ExecuteNonQuery2(command);

            db.EndTransaction();
            db.Close();
            return(ret);
        }
Esempio n. 3
0
        public static int Prestup(int pID, int tID, DatabaseT pDb = null)
        {
            DatabaseT db = new DatabaseT();

            db.Connect();
            Person p = null;
            Team   t = null;

            db.BeginTransaction();
            try
            {
                p = SelectOne(pID);
                t = TeamTable.SelectOne(tID);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(-1);
            }
            if (p.Game_Id.Id != t.Game_Id.Id)
            {
                p.Game_Id.Id = t.Game_Id.Id;
                try
                {
                    Update(p, db);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    db.Rollback();
                    return(-1);
                }
            }
            if (p.Role == "Coach")
            {
                try
                {
                    Team ot = TeamTable.SelectOne(p.Team_Id.Id);
                    ot.Person_Id = null;
                    TeamTable.Update(ot);

                    ot           = TeamTable.SelectOne(tID);
                    ot.Person_Id = p;
                    TeamTable.Update(ot);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    db.Rollback();
                    return(-1);
                }
            }

            OracleCommand command = db.CreateCommand(SQL_UPDATE_PRESTUP);

            command.Parameters.AddWithValue(":team_id", tID);
            command.Parameters.AddWithValue(":id", pID);
            int ret = db.ExecuteNonQuery2(command);

            command.Dispose();
            db.EndTransaction();
            if (pDb == null)
            {
                db.Close();
            }
            return(ret);
        }