当前位置: 首页>>代码示例>>C#>>正文


C# Repository.Single方法代码示例

本文整理汇总了C#中Repository.Single方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Single方法的具体用法?C# Repository.Single怎么用?C# Repository.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Repository的用法示例。


在下文中一共展示了Repository.Single方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        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);
            }
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:55,代码来源:AutoUpdateMonthlyRank.cs

示例2: Single

        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);
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:12,代码来源:BetModels.cs

示例3: Authorize

        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;
                }
            }
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:88,代码来源:AccountModels.cs

示例4: Single

        public static User Single(object providerUserKey)
        {
            Contract.Requires(providerUserKey != null);

            IRepository repo = new Repository();

            return repo.Single<User>(providerUserKey);
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:8,代码来源:AccountModels.cs

示例5: CreateUser

        // 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;
//.........这里部分代码省略.........
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:101,代码来源:AccountModels.cs

示例6: AutoUpdateMonthlyRank_Test

        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);
            }
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:45,代码来源:AcnCasinoTest.cs

示例7: DeleteCampignDefinition

        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);
        }
开发者ID:RagingRudolf,项目名称:uCommerce_migrations,代码行数:8,代码来源:Migrator.cs

示例8: Test_Single_Viewer_Many_FormatException

        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);
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:10,代码来源:RepositoryTest.cs

示例9: Test_Single_Viewer_Many

        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);
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:23,代码来源:RepositoryTest.cs

示例10: Test_Single_Viewer

        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
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:25,代码来源:RepositoryTest.cs

示例11: Test_Single_ArgumentNullException

        public void Test_Single_ArgumentNullException()
        {
            IRepository repo = new Repository();

            repo.Single<League>(null);
            repo.Single<MatchView>(null);
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:7,代码来源:RepositoryTest.cs

示例12: Test_Single_ArgumentException

        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);
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:14,代码来源:RepositoryTest.cs

示例13: Test_Single

        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);
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:19,代码来源:RepositoryTest.cs

示例14: Test_Insert_Update_Delete

        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));
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:48,代码来源:RepositoryTest.cs

示例15: Main

        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();

        }
开发者ID:yonderTech,项目名称:WhiskyTracker,代码行数:97,代码来源:Program.cs


注:本文中的Repository.Single方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。