public int Add(List <UserInfo> t) { UserInfo user = new UserInfo() { Id = GuidTool.GetGuid(), RealName = "Karroy1", UserName = "******", Pwd = "123", // roleId = "1" }; var users = new List <UserInfo>(); users.Add(user); user = new UserInfo() { Id = GuidTool.GetGuid(), RealName = "jay", UserName = "******", Pwd = "123", //roleId = "1" }; users.Add(user); _userRepository.Add(users); return(_userRepository.SaveChanges()); }
public void Add() { var user = new UserInfo() { Id = GuidTool.GetGuid(), RealName = "Karroy", UserName = "******" }; var i = _userService.Add(user); List <UserInfo> users = new List <UserInfo>(); user = new UserInfo() { Id = GuidTool.GetGuid(), RealName = "Karroy", UserName = "******" }; users.Add(user); user = new UserInfo() { Id = GuidTool.GetGuid(), RealName = "jay", UserName = "******" }; users.Add(user); i = _userService.Add(users); }
public void TestAES() { var str = "123456@xs"; str = AESHelper.AESEncrypt(str); str = AESHelper.AESDecrypt(str); var key = GuidTool.GetGuid(); str = AESHelper.AESEncrypt(str, key); str = AESHelper.AESDecrypt(str, key); }
/// <summary> /// 新增菜单 /// </summary> /// <param name="requestModel">参数</param> /// <returns></returns> public ApiResultModel <int> Add(AddMenuRequestModel requestModel) { var result = new ApiResultModel <int>(); if (requestModel.MenuName.IsNullOrEmpty()) { result.Message = "菜单名称不能为空"; return(result); } if (requestModel.ParentId.IsNullOrEmpty()) { result.Message = "上级不能为空"; return(result); } //if (requestModel.Path.IsNullOrEmpty()) //{ // result.Message = "菜单路径不能为空"; // return result; //} if (requestModel.Type == MenuTypeEnum.Module || requestModel.Type == MenuTypeEnum.Function) { var menu = _menuRepository.FirstOrDefault(x => x.name == requestModel.MenuName && x.type == (int)requestModel.Type); if (menu != null) { result.Message = "此菜单名已存在"; return(result); } } var item = new Menu() { id = GuidTool.GetGuid(), name = requestModel.MenuName, parentId = requestModel.ParentId, type = (int)requestModel.Type, sort = requestModel.Sort, path = requestModel.Path ?? "", icon = requestModel.Icon ?? "", }; _menuRepository.Add(item); //_menuRepository.Entry(item).State = EntityState.Added; _menuRepository.SaveChanges(); result.Code = ApiResultCode.Success; return(result); }
/// <summary> /// 生成票据 /// </summary> /// <param name="requestModel"></param> /// <returns></returns> public ApiResultModel <AddAppTicketResponseModel> GetAppTicket(AddAppTicketRequestModel requestModel) { var result = new ApiResultModel <AddAppTicketResponseModel>() { Message = "生成票据失败" }; if (requestModel.AppId.IsNullOrEmpty()) { result.Message = "AppId不能为空"; return(result); } if (requestModel.DeviceNo.IsNullOrEmpty()) { result.Message = "客户端设备号不能为空"; return(result); } var clentType = requestModel.ClientType.GetEnumDescription(); var nonce = Utils.GetNonce(); var ticket = AuthenticationHelper.GetTicket(requestModel.AppId, clentType, requestModel.DeviceNo, nonce); var secret = AuthenticationHelper.GetAppSecret(requestModel.AppId, clentType, requestModel.DeviceNo, nonce); var resultData = new AddAppTicketResponseModel() { Ticket = ticket, AppSecret = secret }; AppTicket model = _db.AppTicket.FirstOrDefault(x => x.AppId == requestModel.AppId && x.ClientType == clentType && x.DeviceNo == requestModel.DeviceNo); if (model == null) { model = new AppTicket() { Id = GuidTool.GetGuid(), AppId = requestModel.AppId, ClientType = clentType, DeviceNo = requestModel.DeviceNo, Noncestr = nonce, AppSecret = secret, Ticket = ticket, LastUpdateTime = DateTime.Now }; _db.AppTicket.Add(model); _db.Entry(model).State = EntityState.Added; _db.SaveChanges(); } else { model.Noncestr = nonce; model.AppSecret = secret; model.Ticket = ticket; model.LastUpdateTime = DateTime.Now; _db.AppTicket.Attach(model); _db.Entry(model).Property(x => x.Noncestr).IsModified = true; _db.Entry(model).Property(x => x.AppSecret).IsModified = true; _db.Entry(model).Property(x => x.Ticket).IsModified = true; _db.Entry(model).Property(x => x.LastUpdateTime).IsModified = true; _db.SaveChanges(); } //缓存 var redisKey = RedisCommon.GetTicketKey(ticket); var redisData = model.MapTo <AppTicketModel>(); RedisClient.Set(RedisDatabase.DB_AuthorityService, redisKey, redisData, 60);//1小时 result.Data = resultData; result.Code = ApiResultCode.Success; return(result); }