public void NewGroup(DataModels.iteam_group header, List <DataModels.iteam_group_user> detail, ref string error)
        {
            using (var db = new DataContext())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var group_name = header?.group_name.Trim();

                        if (string.IsNullOrEmpty(group_name))
                        {
                            throw new Exception("Error : กรุณากรอก Group Name");
                        }

                        header.group_id = (db.iteam_group.Select(x => x.group_id).Max() ?? 0) + 1;
                        header.add_dt   = DateTime.Now;
                        header.add_user = auth.user_id;

                        db.iteam_group.Add(header);
                        db.SaveChanges();

                        if (detail != null && detail.Count() > 0)
                        {
                            foreach (var x in detail)
                            {
                                x.group_id = header.group_id;
                            }
                            db.iteam_group_user.AddRange(detail);
                            db.SaveChanges();
                        }

                        transaction.Commit();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        transaction.Rollback();
                        error = ex.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        error = ex.Message;
                        if (ex.InnerException != null)
                        {
                            error = ex.InnerException.GetBaseException().Message;
                        }
                    }
                }
            }
        }
        public void DeleteGroup(DataModels.iteam_group m, ref string error)
        {
            using (var db = new DataContext())
            {
                db.ExecuteTransaction(() =>
                {
                    var group_id = m?.group_id;

                    db.iteam_group.RemoveRange(db.iteam_group.Where(x => x.group_id == group_id));
                    db.iteam_group_user.RemoveRange(db.iteam_group_user.Where(x => x.group_id == group_id));

                    db.SaveChanges();
                }, ref error);
            }
        }
        public void Editgroup(DataModels.iteam_group header, List <DataModels.iteam_group_user> detail, ref string error)
        {
            using (var db = new DataContext())
            {
                db.ExecuteTransaction(() =>
                {
                    var group_id          = header?.group_id;
                    var group_name        = header?.group_name.Trim();
                    var group_description = header?.group_description;

                    if (string.IsNullOrEmpty(group_name))
                    {
                        throw new Exception("โปรดกรอกชื่อให้ถูกต้อง");
                    }

                    var data_db = db.iteam_group.Where(x => x.group_id == group_id).FirstOrDefault();

                    if (data_db != null)
                    {
                        data_db.group_name = group_name;

                        data_db.group_description = group_description;

                        db.SaveChanges();

                        if (detail != null && detail.Count() > 0)
                        {
                            foreach (var x in detail)
                            {
                                x.group_id = header.group_id;
                            }
                            db.iteam_group_user.AddRange(detail);
                            db.SaveChanges();
                        }
                    }
                }, ref error);
            }
        }