コード例 #1
0
        public bool DecentralizeToChucWithGiaoVien(int tcID, List<int> gvIDList)
        {
            DbTransaction dbTransaction = null;
            using (WebPortalEntities dataEntities = new WebPortalEntities())
            {
                try
                {
                    if (dataEntities.Connection.State == System.Data.ConnectionState.Closed)
                    {
                        dataEntities.Connection.Open();
                    }
                    dbTransaction = dataEntities.Connection.BeginTransaction();

                    //Delete old data for gv & tc
                    var oldTC_GVList = dataEntities.ToChuc_GiaoVien;
                    foreach (var tcgv in oldTC_GVList)
                    {
                        if (tcgv.IDToChuc == tcID)
                        {
                            dataEntities.ToChuc_GiaoVien.DeleteObject(tcgv);
                        }
                    }

                    //Insert new data for gv & tc
                    foreach (var id in gvIDList)
                    {
                        var newGVTC = new Model.ToChuc_GiaoVien();
                        newGVTC.IDGiaoVien = id;
                        newGVTC.IDToChuc = tcID;
                        dataEntities.ToChuc_GiaoVien.AddObject(newGVTC);
                    }

                    if (dataEntities.SaveChanges() != 0)
                    {
                        dbTransaction.Commit();
                        return true;
                    }
                    else
                    {
                        dbTransaction.Rollback();
                        return false;
                    }
                }
                catch
                {
                    dbTransaction.Rollback();
                    return false;
                }
                finally
                {
                    if (dataEntities.Connection.State == System.Data.ConnectionState.Open)
                    {
                        dataEntities.Connection.Close();
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ToChuc_GiaoVien EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToToChuc_GiaoVien(ToChuc_GiaoVien toChuc_GiaoVien)
 {
     base.AddObject("ToChuc_GiaoVien", toChuc_GiaoVien);
 }
コード例 #3
0
 /// <summary>
 /// Create a new ToChuc_GiaoVien object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 public static ToChuc_GiaoVien CreateToChuc_GiaoVien(global::System.Int32 id)
 {
     ToChuc_GiaoVien toChuc_GiaoVien = new ToChuc_GiaoVien();
     toChuc_GiaoVien.ID = id;
     return toChuc_GiaoVien;
 }