public void Test_Single_ArgumentNullException() { IRepository repo = new Repository(); repo.Single <League>(null); repo.Single <MatchView>(null); }
public async void RepositoryCreateDeleteCategories() { using (var context = new JobAssistantContext(_helper.Options)) { var repositoryUnderTest = new Repository(context); int firstId = RandomNumberHelper.NextInteger(); var firstCategory = await repositoryUnderTest.Create <Category>(new Category { CategoryId = firstId, Name = "Test Category " + firstId }); // Was .Result int secondId = RandomNumberHelper.NextInteger(); var secondCategory = await repositoryUnderTest.Create <Category>(new Category { CategoryId = secondId, Name = "Test Category " + secondId }); // Was .Result Assert.Equal("Test Category " + firstId, context.Categories.Single(c => c.CategoryId == firstId).Name); Assert.Equal("Test Category " + secondId, context.Categories.Single(c => c.CategoryId == secondId).Name); await repositoryUnderTest.Delete <Category>(firstCategory); var verifyCategory = repositoryUnderTest.Single <Category>(c => c.CategoryId == firstCategory.CategoryId); Assert.Null(verifyCategory); await repositoryUnderTest.Delete <Category>(secondCategory); verifyCategory = repositoryUnderTest.Single <Category>(c => c.CategoryId == secondCategory.CategoryId); Assert.Null(verifyCategory); } }
public void Test_Single_Viewer() { IRepository repo = new Repository(); // the match has not group var key1 = new Guid("12236a72-f35b-4a0f-90e6-67b11c3364bc"); var instance1 = repo.Single <MatchView>(key1); Assert.IsNotNull(instance1); Assert.IsInstanceOfType(instance1, typeof(MatchView)); Assert.IsNotNull(instance1.CasinoItem); Assert.IsNotNull(instance1.Home); Assert.IsNotNull(instance1.Away); Assert.IsNull(instance1.Group); // no relation group Assert.IsNotNull(instance1.League); Assert.IsNull(instance1.ChoiceOptions); // no relation choiceOptions Init // the match has group var key2 = new Guid("73c314c3-4e50-428d-b698-475fb854e4ea"); var instance2 = repo.Single <MatchView>(key2); Assert.IsNotNull(instance2.Group); // has relation group }
public void Test_Insert_Update_Delete() { var user = new User { UserName = "******", Password = Encrypt.GetMd5Hash("shsict"), EmployeeName = "陈继麟", EmployeeNo = "2607", Department = "智慧交通事业部", Team = "民航与港口行业", Position = "产品总监", Email = "*****@*****.**", Mobile = "13818059707", IsApproved = true, LastLoginDate = DateTime.Today, CreateDate = DateTime.Now, IsActive = true, Remark = "Test Data" }; IRepository repo = new Repository(); object key; repo.Insert(user, out key); Assert.IsNotNull(key); var res = repo.Single <User>(key); Assert.IsNotNull(res); Assert.IsInstanceOfType(res, typeof(User)); res.IsApproved = false; res.IsActive = false; repo.Update(res); var resUpdated = repo.Single <User>(key); Assert.IsNotNull(resUpdated); Assert.IsInstanceOfType(resUpdated, typeof(User)); Assert.IsTrue(resUpdated.Equals(res)); Assert.IsFalse(resUpdated.IsActive); repo.Delete(res); var resDeleted = repo.Single <User>(key); Assert.IsNull(resDeleted); repo.Insert(res); repo.Delete <User>(key); Assert.IsNull(repo.Single <User>(key)); }
public void Single_WhenSingleMatchingItemExists_ReturnsItem() { var expected = new TestData("test"); _subject.StaticData.Add(expected); var result = _subject.Single(c => c.Value == "test"); Assert.Equal(expected, result); }
/// /// <param name="effectCode"></param> public bool CheckEffectCodeExist(string effectCode) { var equipmentEffect = _equipmentEffectDal.Single(s => s.effect_code == effectCode); if (equipmentEffect.HasValue) { return(true); } else { return(false); } }
/// /// <param name="equipmentCode"></param> public Equipment GetEquipment(string equipmentCode) { var equipment = _equipmentDal.Single(s => s.equipment_code == equipmentCode); if (equipment.HasValue) { return(equipment.Entity); } else { return(null); } }
/// /// <param name="equipmentTypeId"></param> public EquipmentType GetEquipmentType(string equipmentTypeCode) { var equipmentType = _equipmentTypeDal.Single(s => s.type_code == equipmentTypeCode); if (equipmentType.HasValue) { return(equipmentType.Entity); } else { return(null); } }
public SysModule GetSysModule(int id) { var sysModuleDal = _sysModuleDal.Single(s => s.id == id); if (sysModuleDal.HasValue) { return(sysModuleDal.Entity); } else { return(null); } }
public SysRight GetSysRight(int id) { var sysRight = _sysRightDal.Single(d => d.id == id); if (sysRight.HasValue) { return(sysRight.Entity); } else { return(null); } }
/// <summary> /// 根据Id获取仓房实例 /// </summary> /// <param name="warehouse_id"></param> /// <returns>返回仓房实例</returns> public Warehouse GetWarehouseById(string warehouse_id) { var warehouse = _warehouseDal.Single(w => w.warehouse_id == warehouse_id); if (warehouse.HasValue) { return(warehouse.Entity); } else { return(null); } }
/// <summary> /// 检测角色编号是否已存在 /// </summary> /// <param name="roleCode">角色编号</param> /// <returns>存在返回true,不存在返回false</returns> public bool CheckRoleCodeExist(string roleCode) { var sysRole = _sysRoleDal.Single(role => role.role_code == roleCode); if (sysRole.HasValue) { return(true); } else { return(false); } }
public ManTeam GetManTeam(string manTeamCode) { var equipmentType = _manTeamDal.Single(s => s.man_team_code == manTeamCode); if (equipmentType.HasValue) { return(equipmentType.Entity); } else { return(null); } }
public BorLine GetBorLine(int id) { var borLine = _borLineDal.Single(d => d.id == id); if (borLine.HasValue) { return(borLine.Entity); } else { return(null); } }
/// <summary> /// 获取根菜单 /// </summary> /// <returns>根菜单实例</returns> public SysMenu GetRootSysMenu() { var rootSysMenu = _sysMenuDal.Single(s => s.menu_parent_id == null); if (rootSysMenu.HasValue) { return(rootSysMenu.Entity); } else { return(null); } }
public bool CheckManRestDayCodeExist(string code) { var manRestDay = _manRestDayDal.Single(m => m.man_restday_code == code); if (manRestDay.HasValue) { return(true); } else { return(false); } }
/// <summary> /// 检测仓库组编号是否已存在 /// </summary> /// <param name="menuCode">仓库组编号</param> /// <returns>若存在,则返回true;若不存在,则返回false</returns> public bool CheckWarehGroupCodeExist(string WarehGroupCode) { var WarehouseGroup = _warehGroupDal.Single(s => s.warehouse_group_id.ToString() == WarehGroupCode); if (WarehouseGroup.HasValue) { return(true); } else { return(false); } }
public SysFunction GetSysFunction(int id) { var sysFunctionDal = _sysFunction.Single(s => s.id == id); if (sysFunctionDal.HasValue) { return(sysFunctionDal.Entity); } else { return(null); } }
public BorGroupMaster GetBorGroupMaster(int id) { var borGroupMaster = _borGroupMasterDal.Single(d => d.id == id); if (borGroupMaster.HasValue) { return(borGroupMaster.Entity); } else { return(null); } }
/// <summary> /// 检测仓库类别编号是否已存在 /// </summary> /// <param name="menuCode">仓库类别编号</param> /// <returns>若存在,则返回true;若不存在,则返回false</returns> public bool CheckWarehTypeCodeExist(int WarehTypeCode) { var WarehType = _warehTypeDal.Single(s => s.warehouse_type_id == WarehTypeCode); if (WarehType.HasValue) { return(true); } else { return(false); } }
public bool CheckExistConsumerTypeCode(string TypeCode) { var eqConsumerType = _eqConsumerTypeDal.Single(s => s.consumer_type_code == TypeCode); if (eqConsumerType.HasValue) { return(true); } else { return(false); } }
public bool CheckAssayNumberExist(string assayNumber) { var assayTemp = _assayDal.Single(ay => ay.assay_number == assayNumber); if (assayTemp.HasValue) { return(true); } else { return(false); } }
/// /// <param name="maintReasonCode"></param> public bool CheckReasonCodeExist(string maintReasonCode) { var maintReasonType = _maintReasonDal.Single(s => s.maint_reason_code == maintReasonCode); if (maintReasonType.HasValue) { return(true); } else { return(false); } }
public BorSection GetBorSection(int id) { var borSection = _borSectionDal.Single(d => d.id == id); if (borSection.HasValue) { return(borSection.Entity); } else { return(null); } }
public PlanTaskBatch GetSinglePlanTaskBatchWithNumber(string batchNumber) { var ptBatch = _planTaskBatchDal.Single(ptb => ptb.plantask_batch_number == batchNumber); if (ptBatch.HasValue) { return(ptBatch.Entity); } else { return(null); } }
public bool CheckWarehUnitTypeCodeExist(string warehUnitTypeCode) { var warehUnitType = _warehUnitTypeDal.Single(w => w.unit_type_code == warehUnitTypeCode); if (warehUnitType.HasValue) { return(true); } else { return(false); } }
public void Test_Single_ArgumentException() { IRepository repo = new Repository(); var key1 = 10000; // require guid, input int repo.Single <League>(key1); repo.Single <MatchView>(key1); var key2 = new Guid(); // require int, input guid repo.Single <Bet>(key2); repo.Single <BetView>(key2); }
public void Test_Insert_Update_Delete() { var org = new League { LeagueName = "test", LeagueOrgName = "t", LeagueSeason = "2015", LeagueTime = DateTime.Now, LeagueLogo = string.Empty, LeagueOrder = 1000, IsActive = true }; IRepository repo = new Repository(); object key; repo.Insert(org, out key); Assert.IsNotNull(key); var res = repo.Single <League>(key); Assert.IsNotNull(res); Assert.IsInstanceOfType(res, typeof(League)); res.IsActive = false; res.LeagueOrder++; repo.Update(res); var resUpdated = repo.Single <League>(key); Assert.IsNotNull(resUpdated); Assert.IsInstanceOfType(resUpdated, typeof(League)); Assert.IsTrue(resUpdated.Equals(res)); Assert.IsFalse(resUpdated.IsActive); repo.Delete(res); var resDeleted = repo.Single <League>(key); Assert.IsNull(resDeleted); repo.Insert(res); repo.Delete <League>(key); Assert.IsNull(repo.Single <League>(key)); }
/// <summary> /// 判断根菜单是否存在 /// </summary> private bool CheckRootMenuExists() { try { Repository<SysMenu> sysMenuDal = _unitOfWork.GetRepository<SysMenu>(); var sysMenu = sysMenuDal.Single(sm => sm.ParentCode == null); if (sysMenu.HasValue) { return true; } return false; } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }
/// <summary> /// 判断方法名称是否存在 /// </summary> /// <param name="name">方法名称</param> private bool CheckNameExists(string functionName) { try { Repository<SysFunction> sysFunctionDal = _unitOfWork.GetRepository<SysFunction>(); var sysDepartment = sysFunctionDal.Single(sd => sd.Name == functionName); if (sysDepartment.HasValue) { return true; } return false; } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }
public void Execute(object state) { var logInfo = new LogInfo { MethodInstance = MethodBase.GetCurrentMethod(), ThreadInstance = Thread.CurrentThread }; try { _log.Info("Scheduler Start: (AutoUpdateMonthlyRank)", logInfo); IRepository repo = new Repository(); var iDay = DateTime.Today; var firstBetDate = repo.Single<Bet>(1).BetTime; while (!(iDay.Year <= firstBetDate.Year && iDay.Month < firstBetDate.Month)) { var winner = GamblerDW.GetTopGamblerMonthly(iDay, RankType.Winner); var loser = GamblerDW.GetTopGamblerMonthly(iDay, RankType.Loser); var rper = GamblerDW.GetTopGamblerMonthly(iDay, RankType.RP); if (winner != null && loser != null) { var day = iDay; var rank = repo.Query<Rank>(x => x.RankYear == day.Year && x.RankMonth == day.Month).FirstOrDefault(); if (rank != null) { //update rank.Init(winner, loser, rper); repo.Update(rank); } else { //insert var instance = new Rank { RankYear = day.Year, RankMonth = day.Month }; instance.Init(winner, loser, rper); repo.Insert(instance); } } iDay = iDay.AddMonths(-1); } _log.Info("Scheduler End: (AutoUpdateMonthlyRank)", logInfo); } catch (Exception ex) { _log.Warn(ex, logInfo); } }
public Definition CampaignItemDefinition(string name, string description) { var definitionTypes = new Repository<DefinitionType>(_sessionProvider); DefinitionType definitionType = definitionTypes.Single(x => x.Name == UCommerce.Definitions.CampaignItem); Definition campaignDefinition = _definitions.Value.SingleOrDefault(x => x.Name == name && x.DefinitionType == definitionType); if (campaignDefinition == null) { campaignDefinition = new Definition { Name = name, Description = description, DefinitionType = definitionType, }; } campaignDefinition.Deleted = false; return campaignDefinition; }
static void Main(string[] args) { AppDomain.CurrentDomain.SetData("DataDirectory", @"D:\Projects\WhiskyTracker\WhiskyTracker.DB"); Repository<Item> itemRepo = new Repository<Item>(); Repository<ItemType> itemTypeRepo = new Repository<ItemType>(); Repository<Price> priceRepo = new Repository<Price>(); /* ItemType h = new ItemType(); List<Item> allItems = itemRepo.GetAll(); List<Price> allPrices = priceRepo.GetAll(); List<object> ai = ( from x in allItems.ToList() select new object() ).ToList().Concat( from y in allPrices.ToList() select new object() ).ToList(); */ foreach (ItemType itemType in itemTypeRepo.GetAll()) { string TargetUrl = string.Format(Config.SAQUrl, itemType.CategoryId, 1024); string HtmlContent = WebTools.SAQTools.GetUrlContentPost(TargetUrl, new NameValueCollection { { "requesttype", "ajax" }, { "searchResultsURL", TargetUrl } }); List<Item> items = WebTools.SAQTools.GetItemsFromContent(HtmlContent); List<Price> prices = new List<Price>(); foreach (Item item in items) { Item dbItem = new Item(); if (itemRepo.IsValid(item)) { item.ItemTypeID = itemType.ID; itemRepo.Add(item); dbItem = item; } else { dbItem = itemRepo.Single(x => x.StoreCode == item.StoreCode); dbItem.ImageURL = item.ImageURL; dbItem.Description = item.Description; dbItem.ABV = item.ABV; dbItem.Size = (item.Size == 0) ? dbItem.Size : item.Size; dbItem.URL = item.URL; dbItem.UPCCode = item.UPCCode; dbItem.Producer = item.Producer; itemRepo.Update(dbItem); } prices.Add(new Price { FetchedDate = DateTime.Now, ItemID = dbItem.ID, Value = item.Price }); List<WaybackMachineTools.Snapshot> archivedUrls = new List<WaybackMachineTools.Snapshot>(); try { archivedUrls = WebTools.WaybackMachineTools.GetItemSnapShots(item.URL); } catch (Exception ex) { Console.WriteLine(string.Format("Error retrieving snapshots for URL {0}: {1}", item.URL, ex.Message)); } foreach (WaybackMachineTools.Snapshot snapshot in archivedUrls) { string archivedContent = WebTools.SAQTools.GetUrlContentGet(snapshot.url); if (archivedContent.IndexOf("<h1>ERREUR</h1>") > 0) continue; var archivedItem = WebTools.SAQTools.GetItemFromContent(archivedContent); item.ImageURL = archivedItem.ImageURL; prices.Add(new Price { Value = archivedItem.Price, FetchedDate = DateTime.ParseExact(snapshot.timestamp.Substring(0, 8), "yyyyMMdd", CultureInfo.InvariantCulture), ItemID = dbItem.ID }); } foreach (Price price in prices) { if (priceRepo.IsValid(price)) priceRepo.Add(price); } prices.Clear(); } } itemRepo.SaveChanges(); priceRepo.SaveChanges(); }
public static BetDto Single(object key) { IRepository repo = new Repository(); var instance = repo.Single<BetView>(key); instance.Many<BetDetail>(x => x.BetID == instance.ID); var mapper = ConfigMapper().CreateMapper(); return mapper.Map<BetDto>(instance); }
public static MatchDto Single(object key) { IRepository repo = new Repository(); var instance = repo.Single<MatchView>(key); instance.Many<ChoiceOption>(x => x.CasinoItemGuid == instance.CasinoItem.ID); var mapper = ConfigMapper().CreateMapper(); return mapper.Map<MatchDto>(instance); }
public static UserWeChat Authorize(Guid userGuid, string accessToken, double expiresIn, string refreshToken, string openId, ScopeType scope, bool anonymous = false) { using (var conn = new SqlConnection(DataAccess.ConnectString)) { conn.Open(); var trans = conn.BeginTransaction(); try { IRepository repo = new Repository(); // 保存微信用户 var user = anonymous ? repo.Single<User>(userGuid) : UserDto.GetSession(); if (user != null && user.ID == userGuid) { var u = new UserWeChat(); if (repo.Any<UserWeChat>(userGuid)) { u = repo.Single<UserWeChat>(userGuid); } u.ID = userGuid; u.UserName = user.UserName; u.LastAuthorizeDate = DateTime.Now; u.AccessToken = accessToken; u.AccessTokenExpiredDate = DateTime.Now.AddSeconds(expiresIn); u.RefreshToken = refreshToken; u.RefreshTokenExpiredDate = DateTime.Now.AddDays(30); u.Gender = 0; if (u.Province == null) u.Province = string.Empty; if (u.City == null) u.City = string.Empty; if (u.Country == null) u.Country = string.Empty; if (u.HeadImgUrl == null) u.HeadImgUrl = string.Empty; if (u.Privilege == null) u.Privilege = string.Empty; if (u.UnionID == null) u.UnionID = string.Empty; repo.Save(u, trans); // 更新普通用户 user.WeChatOpenID = openId; // 按scope,获取微信用户详情 if (scope.Equals(ScopeType.snsapi_userinfo)) { var result = new WeChatSnsClient().GetUserInfo(accessToken, openId); if (!string.IsNullOrEmpty(result)) { var json = JToken.Parse(result); user.WeChatNickName = json["nickname"].Value<string>(); u.Gender = json["sex"].Value<short>(); u.Province = json["province"].Value<string>(); u.City = json["city"].Value<string>(); u.Country = json["country"].Value<string>(); u.HeadImgUrl = json["headimgurl"].Value<string>(); u.Privilege = json["privilege"].Value<JArray>().ToString(); u.UnionID = json["unionid"] != null ? json["unionid"].Value<string>() : string.Empty; repo.Update(u, trans); } } // 更新user的openId, nickname repo.Update(user, trans); trans.Commit(); return u; } return null; } catch { trans.Rollback(); throw; } } }
public static User Single(object providerUserKey) { Contract.Requires(providerUserKey != null); IRepository repo = new Repository(); return repo.Single<User>(providerUserKey); }
public void Test_Single_Viewer_Many() { IRepository repo = new Repository(); var key1 = new Guid("12236a72-f35b-4a0f-90e6-67b11c3364bc"); var instance1 = repo.Single<MatchView>(key1); instance1.Many<ChoiceOption>(x => x.CasinoItemGuid == instance1.CasinoItem.ID); Assert.IsNotNull(instance1); Assert.IsInstanceOfType(instance1, typeof(MatchView)); Assert.IsNotNull(instance1.ChoiceOptions); Assert.IsTrue(instance1.ChoiceOptions.Any()); var instance2 = repo.Single<MatchView>(key1); instance2.Many<ChoiceOption>(x => x.CasinoItemGuid == instance1.ID); Assert.IsNotNull(instance2); Assert.IsInstanceOfType(instance2, typeof(MatchView)); Assert.IsNull(instance2.ChoiceOptions); }
// Summary: // Updates the password for the membership user in the membership data store. // // Parameters: // oldPassword: // The current password for the membership user. // // newPassword: // The new password for the membership user. // // Returns: // true if the update was successful; otherwise, false. // // Exceptions: // System.ArgumentException: // oldPassword is an empty string.-or-newPassword is an empty string. // // System.ArgumentNullException: // oldPassword is null.-or-newPassword is null. // // System.PlatformNotSupportedException: // This method is not available. This can occur if the application targets the // .NET Framework 4 Client Profile. To prevent this exception, override the // method, or change the application to target the full version of the .NET // Framework. public static bool ChangePassword(Membership instance, string oldPassword, string newPassword) { Contract.Requires(!string.IsNullOrEmpty(oldPassword)); Contract.Requires(!string.IsNullOrEmpty(newPassword)); if (oldPassword.Equals(newPassword, StringComparison.OrdinalIgnoreCase)) { throw new Exception("新密码应与旧密码不同"); } if (!instance.Password.Equals(Encrypt.GetMd5Hash(oldPassword))) { throw new Exception("用户旧密码验证不正确"); } using (var conn = new SqlConnection(DataAccess.ConnectString)) { conn.Open(); var trans = conn.BeginTransaction(); try { IRepository repo = new Repository(); instance.Password = Encrypt.GetMd5Hash(newPassword); instance.LastPasswordChangedDate = DateTime.Now; repo.Update(instance, trans); #region Sync Acn User Password if (ConfigGlobal_Arsenal.AcnSync) { var user = repo.Single<User>(instance.ID); if (user?.AcnID != null) { var client = new DiscuzApiClient(); var result = client.UsersChangePassword(user.AcnID.Value, Encrypt.GetMd5Hash(oldPassword), Encrypt.GetMd5Hash(newPassword)); if (!Convert.ToBoolean(result.Replace("\"", ""))) { throw new Exception("ACN同步失败"); } } } #endregion trans.Commit(); return true; } catch { trans.Rollback(); throw; } } }
public void AutoUpdateMonthlyRank_Test() { try { IRepository repo = new Repository(); var iDay = DateTime.Today; var firstBetDate = repo.Single<Bet>(1).BetTime; while (!(iDay.Year <= firstBetDate.Year && iDay.Month < firstBetDate.Month)) { var winner = GamblerDW.GetTopGamblerMonthly(iDay, RankType.Winner); var loser = GamblerDW.GetTopGamblerMonthly(iDay, RankType.Loser); var rper = GamblerDW.GetTopGamblerMonthly(iDay, RankType.RP); if (winner != null && loser != null) { var day = iDay; var rank = repo.Query<Rank>(x => x.RankYear == day.Year && x.RankMonth == day.Month).FirstOrDefault(); if (rank != null) { //update rank.Init(winner, loser, rper); repo.Update(rank); } else { //insert var instance = new Rank { RankYear = day.Year, RankMonth = day.Month }; instance.Init(winner, loser, rper); repo.Insert(instance); } } iDay = iDay.AddMonths(-1); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void Test_Single() { IRepository repo = new Repository(); // correct value of argument var key1 = new Guid("FD32F77D-47A7-4D5F-B7CE-068E3E1A0833"); var instance1 = repo.Single<League>(key1); Assert.IsNotNull(instance1); Assert.IsInstanceOfType(instance1, typeof(League)); // wrong value of argument var key2 = new Guid(); var instance2 = repo.Single<League>(key2); Assert.IsNull(instance2); }
public void Test_Single_ArgumentException() { IRepository repo = new Repository(); var key1 = 10000; // require guid, input int repo.Single<League>(key1); repo.Single<MatchView>(key1); var key2 = new Guid(); // require int, input guid repo.Single<Bet>(key2); repo.Single<BetView>(key2); }
public void Test_Single_ArgumentNullException() { IRepository repo = new Repository(); repo.Single<League>(null); repo.Single<MatchView>(null); }
public void Test_Single_Viewer() { IRepository repo = new Repository(); // the match has not group var key1 = new Guid("12236a72-f35b-4a0f-90e6-67b11c3364bc"); var instance1 = repo.Single<MatchView>(key1); Assert.IsNotNull(instance1); Assert.IsInstanceOfType(instance1, typeof(MatchView)); Assert.IsNotNull(instance1.CasinoItem); Assert.IsNotNull(instance1.Home); Assert.IsNotNull(instance1.Away); Assert.IsNull(instance1.Group); // no relation group Assert.IsNotNull(instance1.League); Assert.IsNull(instance1.ChoiceOptions); // no relation choiceOptions Init // the match has group var key2 = new Guid("73c314c3-4e50-428d-b698-475fb854e4ea"); var instance2 = repo.Single<MatchView>(key2); Assert.IsNotNull(instance2.Group); // has relation group }
public void DeleteCampignDefinition(string name) { var definitionTypes = new Repository<DefinitionType>(_sessionProvider); DefinitionType definitionType = definitionTypes.Single(x => x.Name == UCommerce.Definitions.CampaignItem); Definition campaignDefinition = _definitions.Value.SingleOrDefault(x => x.Name == name && x.DefinitionType == definitionType); _definitions.Value.Delete(campaignDefinition); }
public void Test_Single_Viewer_Many_FormatException() { IRepository repo = new Repository(); var key = new Guid("12236a72-f35b-4a0f-90e6-67b11c3364bc"); var instance = repo.Single<MatchView>(key); instance.Many<League>(x => x.ID == instance.CasinoItem.ID); }
// // Summary: // Gets the information from the data source for the membership user associated // with the specified unique identifier. // // Parameters: // providerUserKey: // The unique user identifier from the membership data source for the user. // // Returns: // A System.Web.Security.MembershipUser object representing the user associated // with the specified unique identifier. // // Exceptions: // System.ArgumentNullException: // providerUserKey is null. public static Membership Single(object providerUserKey) { Contract.Requires(providerUserKey != null); IRepository repo = new Repository(); var membership = repo.Single<Membership>(providerUserKey); return membership; }
public void Test_Insert_Update_Delete() { var org = new League { LeagueName = "test", LeagueOrgName = "t", LeagueSeason = "2015", LeagueTime = DateTime.Now, LeagueLogo = string.Empty, LeagueOrder = 1000, IsActive = true }; IRepository repo = new Repository(); object key; repo.Insert(org, out key); Assert.IsNotNull(key); var res = repo.Single<League>(key); Assert.IsNotNull(res); Assert.IsInstanceOfType(res, typeof(League)); res.IsActive = false; res.LeagueOrder++; repo.Update(res); var resUpdated = repo.Single<League>(key); Assert.IsNotNull(resUpdated); Assert.IsInstanceOfType(resUpdated, typeof(League)); Assert.IsTrue(resUpdated.Equals(res)); Assert.IsFalse(resUpdated.IsActive); repo.Delete(res); var resDeleted = repo.Single<League>(key); Assert.IsNull(resDeleted); repo.Insert(res); repo.Delete<League>(key); Assert.IsNull(repo.Single<League>(key)); }
// Summary: // Adds a new user to the data store. // // Parameters: // username: // The user name for the new user. // // password: // The password for the new user. // // Returns: // A System.Web.Security.MembershipUser object for the newly created user. // // Exceptions: // System.Web.Security.MembershipCreateUserException: // The user was not created. Check the System.Web.Security.MembershipCreateUserException.StatusCode // property for a System.Web.Security.MembershipCreateStatus value. public void CreateUser(string username, string email, string password, out object providerUserKey, out MembershipCreateStatus status) { using (var conn = new SqlConnection(DataAccess.ConnectString)) { conn.Open(); var trans = conn.BeginTransaction(); try { IRepository repo = new Repository(); providerUserKey = null; Init(); #region Check username if (string.IsNullOrEmpty(username)) { status = MembershipCreateStatus.InvalidUserName; return; } if (string.IsNullOrEmpty(email)) { status = MembershipCreateStatus.InvalidEmail; return; } if (ConfigGlobal_Arsenal.AcnSync && GetAcnId(username) > 0) { status = MembershipCreateStatus.DuplicateUserName; return; } if (Single(username) != null) { status = MembershipCreateStatus.DuplicateUserName; return; } UserName = username; #endregion Password = Encrypt.GetMd5Hash(password); Mobile = string.Empty; Email = email; repo.Insert<Membership>(this, out providerUserKey, trans); #region Check user in the data store if (repo.Single<User>(providerUserKey) != null) { status = MembershipCreateStatus.DuplicateProviderUserKey; return; } #endregion var user = new User(); user.ID = (Guid)providerUserKey; user.UserName = UserName; user.IsAnonymous = false; user.LastActivityDate = DateTime.Now; #region Register new Acn User if (ConfigGlobal_Arsenal.AcnSync) { var client = new DiscuzApiClient(); var uid = client.AuthRegister(UserName, Password, Email); user.AcnID = Convert.ToInt32(uid.Replace("\"", "")); user.AcnUserName = UserName; } else { user.AcnID = null; user.AcnUserName = string.Empty; } #endregion user.MemberID = null; user.MemberName = string.Empty; user.WeChatOpenID = null; user.WeChatNickName = string.Empty; repo.Insert(user, trans); trans.Commit(); status = MembershipCreateStatus.Success; } catch (Exception ex) { trans.Rollback(); _log.Error(ex, new LogInfo { MethodInstance = MethodBase.GetCurrentMethod(), ThreadInstance = Thread.CurrentThread }); providerUserKey = null; status = MembershipCreateStatus.ProviderError; } } }
private static void SyncUserWeChatInfo() { IRepository repo = new Repository(); // 7天来未更新的微信会员 或 微信昵称为空的会员 var usersWeChat = repo.Query<UserWeChat>(x => x.LastAuthorizeDate < DateTime.Now.AddDays(-7)); var users = repo.Query<User>(x => x.WeChatOpenID != "") .FindAll(x => string.IsNullOrEmpty(x.WeChatNickName) || usersWeChat.Exists(y => y.ID == x.ID)); if (users.Count > 0 && ConfigGlobal_Arsenal.WeChatActive) { // 根据users,生成输入参数 //{"user_list": [ // { "openid": "otvxTs4dckWG7imySrJd6jSi0CWE", "lang": "zh-CN"}, // { "openid": "otvxTs_JZ6SEiP0imdhpi50fuSZg", "lang": "zh-CN" } // ] //} var mapper = UserWeChatRequestDto.ConfigMapper().CreateMapper(); var userList = new { user_list = mapper.Map<IEnumerable<UserWeChatRequestDto>>(users.DistinctBy(x => x.WeChatOpenID)).ToList() }; var openIds = JsonConvert.SerializeObject(userList); var client = new WeChatApiClient(); var result = client.BatchGetUserInfo(openIds); var json = JToken.Parse(result); if (!string.IsNullOrEmpty(json["user_info_list"].ToString())) { var list = JsonConvert.DeserializeObject<List<UserWeChatResponseDto>>(json["user_info_list"].ToString()); if (list.Count > 0) { foreach (var u in users) { var uResp = list.Find(x => x.openid == u.WeChatOpenID); var uWeChat = repo.Single<UserWeChat>(u.ID); if (uResp != null) { u.WeChatOpenID = uResp.openid; u.WeChatNickName = uResp.nickname; repo.Update(u); if (uWeChat != null) { uWeChat.Gender = uResp.sex; uWeChat.LastAuthorizeDate = DateTime.Now; uWeChat.City = uResp.city ?? string.Empty; uWeChat.Province = uResp.province ?? string.Empty; uWeChat.Country = uResp.country ?? string.Empty; uWeChat.HeadImgUrl = uResp.headimgurl ?? string.Empty; uWeChat.UnionID = uResp.unionid ?? string.Empty; repo.Update(uWeChat); } else { var instance = new UserWeChat { ID = u.ID, UserName = u.UserName, LastAuthorizeDate = DateTime.Now, AccessToken = string.Empty, AccessTokenExpiredDate = DateTime.Now, RefreshToken = string.Empty, RefreshTokenExpiredDate = DateTime.Now, Gender = uResp.sex, Province = uResp.province ?? string.Empty, City = uResp.city ?? string.Empty, Country = uResp.country ?? string.Empty, HeadImgUrl = uResp.headimgurl ?? string.Empty, Privilege = string.Empty, UnionID = uResp.unionid ?? string.Empty }; repo.Insert(instance); } } } } } } }