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


C# ApplicationDbContext.Set方法代码示例

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


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

示例1: RemoveTaskCardAsync

 public async Task RemoveTaskCardAsync(long taskCardId)
 {
     using (var db = new ApplicationDbContext())
     {
         var taskCard = db.Set<TaskCard>().First(x => x.TaskId == taskCardId);
         db.Set<TaskCard>().Remove(taskCard);
         await db.SaveChangesAsync();
     }
 }
开发者ID:yonglisyn,项目名称:PushPull,代码行数:9,代码来源:TaskRepository.cs

示例2: GetFailedTaskCardsAsync

 public async Task<List<TaskCard>> GetFailedTaskCardsAsync(int userId)
 {
     using (var db = new ApplicationDbContext())
     {
         return await db.Set<TaskCard>().Where(x => x.UserId == userId && x.Card.Status == CardStatus.Failed).ToListAsync();
     }
 }
开发者ID:yonglisyn,项目名称:PushPull,代码行数:7,代码来源:TaskRepository.cs

示例3: GetAllTaskCardsAsync

 public async Task<List<TaskCard>> GetAllTaskCardsAsync(int userId)
 {
     using (var db = new ApplicationDbContext())
     {
         return await db.Set<TaskCard>().ToListAsync();
     }
 }
开发者ID:noahteam,项目名称:PushPull,代码行数:7,代码来源:TaskRepository.cs

示例4: AddTaskCardAsync

 public async Task AddTaskCardAsync(TaskCard taskCard)
 {
     using (var db = new ApplicationDbContext())
     {
         db.Set<TaskCard>().Add(taskCard);
         await db.SaveChangesAsync();
     }
 }
开发者ID:yonglisyn,项目名称:PushPull,代码行数:8,代码来源:TaskRepository.cs

示例5: IsValid

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var Name = validationContext.MemberName;

                if (string.IsNullOrEmpty(Name))
                {
                    var displayName = validationContext.DisplayName;

                    var prop = validationContext.ObjectInstance.GetType().GetProperty(displayName);

                    if (prop != null)
                    {
                        Name = prop.Name;
                    }
                    else
                    {
                        var props = validationContext.ObjectInstance.GetType().GetProperties().Where(x => x.CustomAttributes.Count(a => a.AttributeType == typeof(DisplayAttribute)) > 0).ToList();

                        foreach (PropertyInfo prp in props)
                        {
                            var attr = prp.CustomAttributes.FirstOrDefault(p => p.AttributeType == typeof(DisplayAttribute));

                            var val = attr.NamedArguments.FirstOrDefault(p => p.MemberName == "Name").TypedValue.Value;

                            if (val.Equals(displayName))
                            {
                                Name = prp.Name;
                                break;
                            }
                        }
                    }
                }

                PropertyInfo IdProp = validationContext.ObjectInstance.GetType().GetProperties().FirstOrDefault(x => x.CustomAttributes.Count(a => a.AttributeType == typeof(KeyAttribute)) > 0);

                int Id = (int)IdProp.GetValue(validationContext.ObjectInstance, null);

                Type entityType = validationContext.ObjectType;

                var result = db.Set(entityType).Where(Name + "[email protected]", value);
                int count = 0;

                if (Id > 0)
                {
                    result = result.Where(IdProp.Name + "<>@0", Id);
                }

                count = result.Count();

                if (count == 0)
                    return ValidationResult.Success;
                else
                    return new ValidationResult(ErrorMessageString);
            }
        }
开发者ID:fatihBulbul,项目名称:UniqueAttribute,代码行数:57,代码来源:Unique.cs

示例6: EditTaskCardAsync

 public async Task<TaskCard> EditTaskCardAsync(TaskCard taskCard)
 {
     using (var db = new ApplicationDbContext())
     {
         db.Set<TaskCard>().AddOrUpdate(taskCard);
         await db.SaveChangesAsync();
         return taskCard;
     }
 }
开发者ID:yonglisyn,项目名称:PushPull,代码行数:9,代码来源:TaskRepository.cs

示例7: UpdateStatus

 public async Task<TaskCard> UpdateStatus(long taskCardId, CardStatus status)
 {
     using (var db = new ApplicationDbContext())
     {
         var taskCard = db.Set<TaskCard>().First(x => x.TaskId == taskCardId);
         taskCard.Card.Status = status;
         await db.SaveChangesAsync();
         return taskCard;
     }
 }
开发者ID:yonglisyn,项目名称:PushPull,代码行数:10,代码来源:TaskRepository.cs

示例8: CheckUserToken

        private bool CheckUserToken(string confirmationToken)
        {
            var context = new ApplicationDbContext();
            ApplicationUser user = context.Users.SingleOrDefault(applicationUser => applicationUser.ConfirmationToken == confirmationToken);
            if (user == null) return false;

            user.IsConfirmed = true;
            DbSet<ApplicationUser> applicationUsers = context.Set<ApplicationUser>();
            applicationUsers.Attach(user);
            context.Entry(user).State = EntityState.Modified;
            context.SaveChanges();
            return true;
        }
开发者ID:serg-sr,项目名称:CatchThemAll,代码行数:13,代码来源:AccountController.cs

示例9: SqlTool

        public JsonResult SqlTool(string query)
        {
            var type = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(t => t.Name == query);
            ApplicationDbContext context = new ApplicationDbContext();
            DbSet contextDbSet;

            contextDbSet = context.Set(type);

            return Json(contextDbSet.ToString());
        }
开发者ID:MaltheFriisberg,项目名称:Fall2015,代码行数:10,代码来源:CompetenciesController.cs

示例10: Configure

        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="loggerFactory"></param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddNLog();

            try
            {
                using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
                    .CreateScope())
                {
                    serviceScope.ServiceProvider.GetService<BddContext>()
                         .Database.Migrate();
                    serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
                         .Database.Migrate();
                    serviceScope.ServiceProvider.GetService<BddContext>().EnsureSeedData();
                }
            }
            catch { }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }

            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseIdentity();

            app.UseOAuthValidation();

            app.UseOpenIddict();

            app.UseGoogleAuthentication(new GoogleOptions()
            {
                ClientId = Configuration["GOOGLE_CLIENT_ID"],
                ClientSecret = Configuration["GOOGLE_CLIENT_SECRET"]
            });

            app.UseFacebookAuthentication(new FacebookOptions()
            {
                AppId = Configuration["FACEBOOK_APP_ID"],
                AppSecret = Configuration["FACEBOOK_SECRET_ID"]
            });

            app.UseMiddleware<WebAPILoggerMiddleware>();

            app.UseMvc(routes =>
            {
                routes.MapRoute("journee",
                    template: "Journee/Index/{equipe}/{idJournee}", defaults: new { controller = "Journee", action="Index", equipe="equipe1", idJournee = 1});
                routes.MapRoute("actu",
                    template: "Journee/Detail/{url}", defaults: new { controller = "Journee", action = "Index", equipe = "equipe1", idJournee = 1 });
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Actu}/{action=Index}/{id?}");
            });

            app.UseSwagger();
            app.UseSwaggerUi();

            app.AddNLogWeb();

            using (var context = new ApplicationDbContext(app.ApplicationServices.GetRequiredService<DbContextOptions<ApplicationDbContext>>()))
            {
                context.Database.EnsureCreated();

                var applications = context.Set<OpenIddictApplication>();
                // Add Mvc.Client to the known applications.
                if (!applications.Any())
                {
                    // Note: when using the introspection middleware, your resource server
                    // MUST be registered as an OAuth2 client and have valid credentials.
                    //
                    // context.Applications.Add(new OpenIddictApplication {
                    //     Id = "resource_server",
                    //     DisplayName = "Main resource server",
                    //     Secret = Crypto.HashPassword("secret_secret_secret"),
                    //     Type = OpenIddictConstants.ClientTypes.Confidential
                    // });

                    applications.Add(new OpenIddictApplication
                    {
                        ClientId = "xamarin-auth",
                        ClientSecret = Crypto.HashPassword(Configuration["OPENIDDICT_CLIENT_SECRET"]),
                        DisplayName = "HOFC",
                        LogoutRedirectUri = "https://local.webhofc.fr/",
                        RedirectUri = "urn:ietf:wg:oauth:2.0:oob",
//.........这里部分代码省略.........
开发者ID:orome656,项目名称:HOFCServerNet,代码行数:101,代码来源:Startup.cs

示例11: ExternalLoginCallback

        public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
            if (loginInfo == null)
            {
                return RedirectToAction("Login");
            }

            var externalIdentity = HttpContext.GetOwinContext().Authentication.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
            var emailClaim = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);
            var email = emailClaim.Value;
            var nameClaim = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name);
            var name = nameClaim.Value;

            // Sign in the user with this external login provider if the user already has a login
            var user = await UserManager.FindAsync(loginInfo.Login);
            if (user != null)
            {
                await SignInAsync(user, isPersistent: false);
                return RedirectToLocal(returnUrl);
            }
            else
            {
                // If the user does not have an account, then prompt the user to create an account
                // If the user does not have an account, then create one for them.
                ViewBag.ReturnUrl = returnUrl;
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider;

                using (ApplicationDbContext db = new ApplicationDbContext())
                {                    
                    Int32 count = db.Set<IdentityUser>().Count();
                    var user1 = new ApplicationUser() { UserName = "user" + count.ToString() };
                    var result = await UserManager.CreateAsync(user1);
                    if (result.Succeeded)
                    {
                        result = await UserManager.AddLoginAsync(user1.Id, loginInfo.Login);
                        if (result.Succeeded)
                        {
                            var appuser = new AppUser() { UserID = user1.Id, Email = email, Name = name };
                            db.AppUsers.Add(appuser);
                            db.SaveChanges();
                            await SignInAsync(user1, isPersistent: false);
                            return RedirectToLocal(returnUrl);
                        }
                    }
                }

                return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { UserName = loginInfo.DefaultUserName });
            }
        }
开发者ID:processnotproduct,项目名称:DevFestEvent-MVC,代码行数:50,代码来源:AccountController.cs

示例12: GiftRepository

 //Constuctor
 public GiftRepository(ApplicationDbContext dbContext)
 {
     _dbContext = dbContext;
     _dbSet = dbContext.Set<Gift>();
 }
开发者ID:couscousbzh,项目名称:Toyalist1,代码行数:6,代码来源:GiftRepository.cs


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