Exemple #1
0
        public async Task <IActionResult> Login(Accounts inputModel)
        {
            try
            {
                var account = await _accountManager.Login(inputModel.UserName, inputModel.Password);

                if (account == null)
                {
                    return(Json(new { Result = false, Message = "Tài khoản hoặc mật khẩu không đúng" }));
                }
                if (account != null)
                {
                    account.Token        = CreateToken();
                    account.ExpiredToken = DateTime.Now.AddHours(12);
                    await _accountManager.UpdateToken(account);

                    var employ = await _employeeManager.Find_By_Id(account.EmployeeId);

                    var job = await _jobPositionsManager.Find_By_Id(employ.JobPositionId);

                    account.EmployeeName    = employ.Name;
                    account.JobPositionName = job.Name;
                    Portal.Utils.SessionExtensions.Set <Accounts>(_session, Portal.Utils.SessionExtensions.SessionAccount, account);
                    Portal.Utils.SessionExtensions.Set <List <Permissions> >(_session, Portal.Utils.SessionExtensions.SesscionPermission, account.ListPermissions);
                    return(Json(new { Result = true, Message = "Đăng nhập thành công" }));
                }
                return(Json(new { Result = false, Message = "Đăng nhập không thành công" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = false, Message = ex.Message }));
            }
        }
        public async Task <IActionResult> Update(long id)
        {
            try
            {
                var data = await _jobPositionsManager.Find_By_Id(id);

                return(PartialView("_Update", data));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = false, Message = ex.Message }));
            }
        }