Example #1
0
        public static int DeleteGroupByGroupID(int groupID)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            var group = db.tblGroups.Where(g => g.GroupID == groupID).FirstOrDefault();

            if (group == null)
            {
                return(0);
            }

            //delete group
            db.DeleteObject(group);

            //delete group's users in tblUserInGroup
            List <tblUserInGroup> listTblUserInGroup = db.tblUserInGroups.Where(g => g.GroupID == groupID).ToList();

            foreach (tblUserInGroup userInGroup in listTblUserInGroup)
            {
                db.DeleteObject(userInGroup);
            }

            //delete group's permission in tblUserGroupPermistion
            List <tblUserGroupPermission> listUserGroupPermission = db.tblUserGroupPermissions.Where(g => g.GroupID == groupID && g.PermissionType == UserGroupPermissionFactory.PERMISSION_TYPE_GROUP).ToList();

            foreach (tblUserGroupPermission userGroupPermission in listUserGroupPermission)
            {
                db.DeleteObject(userGroupPermission);
            }

            int re = db.SaveChanges();

            db.Connection.Close();
            return(re);
        }
        public static int Delete(Int64 ID)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            try
            {
                var reply = db.tblListHandoverReplies.FirstOrDefault(vt => vt.ID == ID);
                if (reply == null)
                {
                    return(0);
                }
                else
                {
                    //update all related Handover
                    RemoveListReplyIDFromHandover(ID);

                    //delete Bang ke hoi bao
                    db.DeleteObject(reply);
                    return(db.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
            finally
            {
                db.Dispose();
            }
        }
Example #3
0
        public static int Delete(long trainId)
        {
            var db    = new dbTrainEntities(ConnectionController.GetConnection());
            var train = db.tblTrains.FirstOrDefault(g => g.TrainID == trainId);

            db.DeleteObject(train);
            return(db.SaveChanges());
        }
Example #4
0
        public static int Delete(String companyCode)
        {
            var db      = new dbTrainEntities(ConnectionController.GetConnection());
            var company = db.tblCompanies.FirstOrDefault(vt => vt.CompanyCode == companyCode);

            db.DeleteObject(company);
            return(db.SaveChanges());
        }
Example #5
0
        public static int DeleteType(String typeCode)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            var type = db.tblTypes.FirstOrDefault(vt => vt.TypeCode == typeCode);

            db.DeleteObject(type);
            return(db.SaveChanges());
        }
Example #6
0
        public static int Delete(String customsCode)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());

            var customs = db.tblCustoms.FirstOrDefault(g => g.CustomsCode == customsCode);

            db.DeleteObject(customs);
            return(db.SaveChanges());
        }
        public static int DeleteUserInGroup(int groupID, int userID)
        {
            var            db             = new dbTrainEntities(ConnectionController.GetConnection());
            tblUserInGroup tblUserInGroup = db.tblUserInGroups.Where(g => g.GroupID == groupID && g.UserID == userID).FirstOrDefault();

            if (tblUserInGroup != null)
            {
                db.DeleteObject(tblUserInGroup);
            }
            int re = db.SaveChanges();

            db.Connection.Close();
            return(re);
        }
        public static int DeleteUserInGroupByGroupID(Int32 groupID)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());
            List <tblUserInGroup> listTblUserInGroup = db.tblUserInGroups.Where(g => g.GroupID == groupID).ToList();

            foreach (tblUserInGroup userInGroup in listTblUserInGroup)
            {
                db.DeleteObject(userInGroup);
            }
            int re = db.SaveChanges();

            db.Connection.Close();
            return(re);
        }
Example #9
0
        public static int DeleteUserGroupPermissionByUserID(int userID)
        {
            var db = new dbTrainEntities(ConnectionController.GetConnection());
            List <tblUserGroupPermission> listUserGroupPermission = db.tblUserGroupPermissions.Where(g => g.UserID == userID && g.PermissionType == PERMISSION_TYPE_USER).ToList();

            foreach (tblUserGroupPermission userGroupPermission in listUserGroupPermission)
            {
                db.DeleteObject(userGroupPermission);
            }
            int re = db.SaveChanges();

            db.Connection.Close();
            return(re);
        }
Example #10
0
 /// <summary>
 /// Deletes the specified user ID.
 /// </summary>
 /// <param name="userID">The user ID.</param>
 /// <returns></returns>
 public static int Delete(int userID)
 {
     try
     {
         var db   = new dbTrainEntities(ConnectionController.GetConnection());
         var user = db.tblUsers.Where(g => g.UserID.Equals(userID)).FirstOrDefault();
         db.DeleteObject(user);
         return(db.SaveChanges());
     }
     catch (Exception ex)
     {
         //logger.Error(ex.ToString());
         throw;
     }
 }