public override async void LoadDataForm() { _iEntry = _iEntry ?? new xPermission(); _aEntry = await clsPermission.Instance.GetByID(_iEntry.KeyID); LoadUserFeature(_aEntry.KeyID); SetControlValue(); }
public override void RenewData() { _iEntry = _aEntry = null; }
public async Task <IActionResult> InitUser() { aModel db = new aModel(); DateTime time = DateTime.Now; try { await db.Database.BeginTransactionAsync(); xPermission permission = new xPermission() { KeyID = 0, Ma = "ADMIN", Ten = "ADMIN", NgayTao = time }; await db.xPermission.AddAsync(permission); await db.SaveChangesAsync(); xPersonnel personnel = new xPersonnel() { KeyID = 0, Ma = "NV0001", Ten = "Nhân viên 0001", NgayTao = time }; await db.xPersonnel.AddAsync(personnel); await db.SaveChangesAsync(); xAccount account = new xAccount() { KeyID = personnel.KeyID, NgayTao = time, PersonelName = personnel.Ten, UserName = "******", Password = "******", IDPermission = permission.KeyID, PermissionName = permission.Ten }; await db.xAccount.AddAsync(account); await db.SaveChangesAsync(); List <xFeature> features = await db.xFeature.ToListAsync(); List <xUserFeature> userFeatures = new List <xUserFeature>(); foreach (xFeature f in features) { userFeatures.Add(new xUserFeature() { KeyID = 0, IDPermission = permission.KeyID, PermissionName = permission.Ten, IDFeature = f.KeyID, Controller = f.Controller, Action = f.Action, Method = f.Method, Template = f.Template, Path = f.Path, NgayTao = time }); } await db.xUserFeature.AddRangeAsync(userFeatures.ToArray()); await db.SaveChangesAsync(); db.Database.CommitTransaction(); return(Ok(userFeatures)); } catch (Exception ex) { db.Database.RollbackTransaction(); ModelState.AddModelError("Exception_Message", ex.Message); return(BadRequest(ModelState)); } }