예제 #1
0
        public void saveDetail(sys_group_user_model model)
        {
            var delete1 = _context.sys_group_user_details.Where(t => t.id_group_user == model.db.id);

            _context.RemoveRange(delete1);
            _context.SaveChanges();
            model.list_item.ForEach(t =>
            {
                t.db.id            = 0;
                t.db.id_group_user = model.db.id;
            });
            var listInsert1 = model.list_item.Select(d => d.db).ToList();

            _context.sys_group_user_details.AddRange(listInsert1);
            _context.SaveChanges();


            var delete = _context.sys_group_user_roles.Where(t => t.id_group_user == model.db.id);

            _context.RemoveRange(delete);
            _context.SaveChanges();
            model.list_role.ForEach(t =>
            {
                t.db.id            = 0;
                t.db.id_group_user = model.db.id;
            });
            var listInsert = model.list_role.Select(d => d.db).ToList();

            _context.sys_group_user_roles.AddRange(listInsert);
            _context.SaveChanges();
        }
예제 #2
0
        public async Task <int> insert(sys_group_user_model model)
        {
            await _context.sys_group_users.AddAsync(model.db);

            _context.SaveChanges();
            saveDetail(model);
            return(1);
        }
예제 #3
0
        public int update(sys_group_user_model model)
        {
            var db = _context.sys_group_users.Where(d => d.id == model.db.id).FirstOrDefault();

            db.status_del  = model.db.status_del;
            db.name        = model.db.name;
            db.note        = model.db.note;
            db.update_by   = model.db.update_by;
            db.update_date = model.db.update_date;

            _context.SaveChanges();
            if (model.db.status_del == 1)
            {
                saveDetail(model);
            }

            return(1);
        }
예제 #4
0
        private bool checkModelStateCreateEdit(ActionEnumForm action, sys_group_user_model item)
        {
            if (string.IsNullOrEmpty(item.db.name))
            {
                ModelState.AddModelError("db.name", "required");
            }
            var search = repo.FindAll().Where(d => d.db.name == item.db.name && d.db.id != item.db.id).Count();

            if (search > 0)
            {
                ModelState.AddModelError("db.name", "existed");
            }
            if (item.list_item.Count == 0 && action == ActionEnumForm.create)
            {
                ModelState.AddModelError("list_item", "required");
            }



            return(ModelState.IsValid);
        }
예제 #5
0
 private bool checkModelStateEdit(sys_group_user_model item)
 {
     return(checkModelStateCreateEdit(ActionEnumForm.edit, item));
 }