Beispiel #1
0
        public static bool CheckExist(this UnitOfWork instance, string username)
        {
            xAccount account = instance.GetRepository <xAccount>().GetItems().FirstOrDefault(x => x.Username.ToLower().Equals(username.ToLower()));

            if (account != null)
            {
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        HttpStatusCode CheckRole(ActionExecutingContext context)
        {
            try
            {
                Controller controller = (Controller)context.Controller;

                //IPAddress address = context.HttpContext.Connection.RemoteIpAddress;

                //ControllerActionDescriptor descriptor = (ControllerActionDescriptor)context.ActionDescriptor;
                //string MethodName = context.HttpContext.Request.Method.ToLower();
                //string ControllerName = descriptor.ControllerName.ToLower();
                //string ActionName = descriptor.ActionName.ToLower();
                //string TemplateName = descriptor.AttributeRouteInfo.Template.ToLower();

                ControllerActionDescriptor descriptor = (ControllerActionDescriptor)context.ActionDescriptor;
                string MethodName     = context.HttpContext.Request.Method.ToLower();
                string ControllerName = descriptor.ControllerName.ToLower();
                string ActionName     = descriptor.ActionName.ToLower();
                string TemplateName   = descriptor.AttributeRouteInfo.Template.ToLower();

                aModel db = new aModel();

                xAccount account = db.xAccount.Find(Convert.ToInt32(controller.Request.Headers["IDAccount"].ToList()[0]));
                if (account == null)
                {
                    return(HttpStatusCode.BadRequest);
                }

                xUserFeature userFeature = db.xUserFeature
                                           .FirstOrDefault(x =>
                                                           x.IDPermission == account.IDPermission &&
                                                           x.Controller.Equals(ControllerName) &&
                                                           x.Action.Equals(ActionName) &&
                                                           x.Method.Equals(MethodName) &&
                                                           x.Path.Equals(TemplateName));

                if (userFeature == null)
                {
                    return(HttpStatusCode.BadRequest);
                }

                if (userFeature.TrangThai == 3)
                {
                    return(HttpStatusCode.BadRequest);
                }

                return(HttpStatusCode.OK);
            }
            catch
            {
                return(HttpStatusCode.BadRequest);
            }
        }
Beispiel #3
0
        public override async void LoadDataForm()
        {
            _iEntry = _iEntry ?? new xAccount()
            {
                IsEnable = true
            };
            _aEntry = await clsAccount.Instance.GetByID(_iEntry.KeyID);

            LoadPersonnel(_aEntry.KeyID);
            LoadPermission(_aEntry.IDPermission);
            SetControlValue();
        }
 public async static Task <bool> Check_Role(xAccount _iAccount, string cName)
 {
     //db = db ?? new aModel();
     //if (_iAccount.KeyID == 0)
     //    return true;
     //else if (_iAccount.IDPermission == 0)
     //    return false;
     //else
     //{
     //    xPermission permission = await clsPermission.Instance.GetByID(_iAccount.IDPermission) ?? new xPermission();
     //    List<xUserFeature> lstRoles = new List<xUserFeature>(clsUserRole.Instance.GetUserFeature(permission.KeyID));
     //    return lstRoles.Any(n => n.IsEnable && n.IDFeature.Contains(cName));
     //}
     return(await Task.Factory.StartNew(() => { return true; }));
 }
Beispiel #5
0
        public static Define.fLogin CheckLogin(this UnitOfWork instance, string username, string password)
        {
            xAccount account = instance.GetRepository <xAccount>().GetItems().FirstOrDefault(x => x.Username.ToLower().Equals(username.ToLower()) && x.Password.ToLower().Equals(password.ToLower()));

            if (account != null)
            {
                if (account.IsEnable)
                {
                    return(Define.fLogin.Success);
                }
                else
                {
                    return(Define.fLogin.Disable);
                }
            }
            else
            {
                return(Define.fLogin.NotFound);
            }
        }
 public override void UpdateEntry()
 {
     if (grvAccountList.RowCount > 0 && grvAccountList.FocusedRowHandle >= 0)
     {
         try
         {
             using (frmAccount _frm = new frmAccount())
             {
                 xAccount _eEntry = (xAccount)grvAccountList.GetRow(grvAccountList.FocusedRowHandle);
                 _frm._iEntry     = _eEntry;
                 _frm.Text        = "Cập nhật tài khoản";
                 _frm.fType       = eFormType.Edit;
                 _frm._ReloadData = this.LoadData;
                 _frm.ShowDialog();
             }
         }
         catch (Exception ex)
         {
             clsGeneral.showErrorException(ex, "Exception");
         }
     }
 }
Beispiel #7
0
        public async Task <IActionResult> Login([FromHeader] string Username, [FromHeader] string Password)
        {
            aModel db = new aModel();

            try
            {
                if (string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(Password))
                {
                    throw new Exception("Username hoặc Password không hợp lệ");
                }

                xAccount account = await db.xAccount.FirstOrDefaultAsync(x => x.UserName.ToLower().Equals(Username.ToLower()) && x.Password.ToLower().Equals(Password.ToLower()));

                if (account == null)
                {
                    throw new Exception("Tài khoản không tồn tại");
                }

                xPersonnel personnel = await db.xPersonnel.FindAsync(account.KeyID);

                if (personnel == null)
                {
                    throw new Exception("Nhân viên không tồn tại");
                }

                UserInfo user = new UserInfo()
                {
                    xPersonnel = personnel,
                    xAccount   = account
                };

                return(Ok(user));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Exception_Message", ex.Message);
                return(BadRequest(ModelState));
            }
        }
Beispiel #8
0
 public override void RenewData()
 {
     _iEntry = _aEntry = null;
 }
        public static bool CheckUser_Login(string _UserName, string _Password, xPersonnel personnel, xAccount account)
        {
            //try
            //{
            //    db = new aModel();
            //    account = db.xAccount.FirstOrDefault(n => n.UserName.Equals(_UserName) && n.Password.Equals(_Password));
            //    if (account != null)
            //    {
            //        personnel = db.xPersonnel.FirstOrDefault(x => x.KeyID == account.KeyID && x.IsEnable && x.IsAccount);

            //        if (personnel != null)
            //        {
            //            clsGeneral.curAccount = account;
            //            clsGeneral.curPersonnel = personnel;
            //            clsGeneral.curUserFeature = new xUserFeature() { IsEnable = true };
            //            return true;
            //        }
            //        else
            //            return false;
            //    }
            //    else
            //        return false;
            //}

            return(true);
            //catch { return false; }
        }
Beispiel #10
0
        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));
            }
        }