Exemple #1
0
        public static int Delete(int id, DatabaseT pDb = null)
        {
            DatabaseT db = new DatabaseT();

            db.Connect();
            OracleCommand command = db.CreateCommand(SQL_DELETE_ID);

            Person p = PersonTable.SelectOne(id);

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

            command.Parameters.AddWithValue(":id", id);
            int ret = db.ExecuteNonQuery(command);

            db.Close();
            return(ret);
        }
Exemple #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);
        }