public virtual async Task <IDataResponse <TModel> > InsertAsync(TModel model) { var result = await _dal.InsertAsync(_mapper.Map <TEntity>(model)); if (!result.Success) { return(new ErrorDataResponse <TModel>(result.Message)); } return(new SuccessDataResponse <TModel>(_mapper.Map <TModel>(result.Data))); }
private async Task <IDataResponse <string> > LoginAsync(Account account) { if (account == null) { return(new ErrorDataResponse <string>(null, AccountMessage.AccountNotFound)); } if (account.IsBlocked) { return(new ErrorDataResponse <string>(null, AccountMessage.AccountIsBlocked)); } await _loginHistory.InsertAsync(new AccountLoginHistory { AccountId = account.Id, Date = DateTime.Now, IsSuccess = true, IpAddress = _helper.GetIpAddress(), Message = AccountMessage.LoginSuccessful.Left(255) }); var accessToken = _jwtService.CreateToken(account.Id); var rules = await _ruleDal.TableNoTracking.Where(x => x.RoleId == account.RoleId).ToListAsync(); await _userCachingService.Set(account.Id, new UserInfo { AccountId = account.Id, FullName = $"{account.FirstName} {account.LastName}", IsSuperVisor = account.IsSuperVisor, Token = accessToken, Rules = account.IsSuperVisor ? null : rules.Select(x => new UserRules { ModuleName = x.Module.ToString(), View = x.View, Insert = x.Insert, Update = x.Update, Delete = x.Delete }).ToList() }); return(new SuccessDataResponse <string>(accessToken.Token, "")); }