本文整理汇总了C#中ApplicationDbContext类的典型用法代码示例。如果您正苦于以下问题:C# ApplicationDbContext类的具体用法?C# ApplicationDbContext怎么用?C# ApplicationDbContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApplicationDbContext类属于命名空间,在下文中一共展示了ApplicationDbContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Index
// GET: Home
public async Task<ActionResult> Index()
{
var context = new ApplicationDbContext(); // DefaultConnection
var store = new UserStore<CustomUser>(context);
var manager = new UserManager<CustomUser>(store);
var email = "[email protected]";
var password = "Passw0rd";
var user = await manager.FindByEmailAsync(email);
if (user == null)
{
user = new CustomUser
{
UserName = email,
Email = email,
FirstName = "Super",
LastName = "Admin"
};
await manager.CreateAsync(user, password);
}
else
{
user.FirstName = "Super";
user.LastName = "Admin";
await manager.UpdateAsync(user);
}
return Content("Hello, Index");
}
开发者ID:shayim,项目名称:authentication-with-aspnet-identity,代码行数:34,代码来源:HomeController.cs
示例2: AddFollow
public string AddFollow(string userId, string type)
{
using (ApplicationDbContext db = new ApplicationDbContext())
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
var currentUser = manager.FindById(User.Identity.GetUserId());
var followedUser = manager.FindById(userId);
if (type.Equals("Follow"))
{
currentUser.followList.Add(followedUser);
}
else
{
UnFollow(currentUser, followedUser);
}
//manager.UpdateAsync(currentUser);
var store = new UserStore<ApplicationUser>(new ApplicationDbContext());
//store.Context.SaveChanges();
db.SaveChanges();
return "success";
}
}
开发者ID:yippee-ki-yay,项目名称:Codetweets,代码行数:26,代码来源:FeedController.cs
示例3: AddBlock
public string AddBlock(string userId, string type)
{
using (ApplicationDbContext db = new ApplicationDbContext())
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
var currentUser = manager.FindById(User.Identity.GetUserId());
var blockedUser = manager.FindById(userId);
if (type.Equals("Block"))
{
currentUser.blockedList.Add(blockedUser);
//unfollow each person if there was any following
UnFollow(currentUser, blockedUser);
UnFollow(blockedUser, currentUser);
}
else //unblock user just remove him from the list
{
var block = currentUser.blockedList.Find(user => user.Id == blockedUser.Id);
if (block != null)
{
currentUser.blockedList.Remove(block);
}
}
// manager.UpdateAsync(currentUser);
var store = new UserStore<ApplicationUser>(new ApplicationDbContext());
// store.Context.SaveChanges();
db.SaveChanges();
return "success";
}
}
开发者ID:yippee-ki-yay,项目名称:Codetweets,代码行数:35,代码来源:FeedController.cs
示例4: grdMessages_RowCommand
protected void grdMessages_RowCommand(object sender, GridViewCommandEventArgs e)
{
Control control = null;
switch (e.CommandName)
{
case "AddFromFooter":
control = grdMessages.FooterRow;
break;
default:
control = grdMessages.Controls[0].Controls[0];
break;
}
if (control != null)
{
var textBox = control.FindControl("txtMessage") as TextBox;
if (textBox != null)
{
string message = textBox.Text;
var db = new ApplicationDbContext();
db.Messages.Add(new MessageModel()
{
Message = message,
UserId = User.Identity.GetUserId()
});
db.SaveChanges();
grdMessages.DataBind();
}
}
}
开发者ID:NikolayKostadinov,项目名称:TelerikAkademy,代码行数:30,代码来源:Default.aspx.cs
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//var manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
//manager.Roles.CreateRoleAsync(new Role("Moderator"));
//manager.Roles.AddUserToRoleAsync("54fbcab5-d65b-47d4-b517-2eba10002e21", "186c2138-de27-42a6-94f0-8b830c2e8b9c");
var manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
if (!manager.Logins.HasLocalLogin(User.Identity.GetUserId()))
{
grdMessages.EmptyDataTemplate = null;
if (grdMessages.FooterRow != null)
{
grdMessages.FooterRow.Visible = false;
}
}
else
{
var userId = User.Identity.GetUserId();
var db = new ApplicationDbContext();
var user = db.Users.FirstOrDefault(u => u.Id == userId);
if (user != null)
{
if (user.Roles.Any(r => r.Role.Name == "Moderator"))
{
grdMessages.Columns[2].Visible = true;
}
else if (user.Roles.Any(r => r.Role.Name == "Administrator"))
{
grdMessages.Columns[2].Visible = true;
grdMessages.Columns[3].Visible = true;
}
}
}
}
开发者ID:NikolayKostadinov,项目名称:TelerikAkademy,代码行数:34,代码来源:Default.aspx.cs
示例6: GetAll
public static IEnumerable<Language> GetAll()
{
using (ApplicationDbContext db = new ApplicationDbContext())
{
return db.Languages.OrderBy(h => h.Name).ToList();
}
}
开发者ID:sbjaoui,项目名称:Jobs4Developers,代码行数:7,代码来源:LanguageManager.cs
示例7: LogIn
protected void LogIn(object sender, EventArgs e)
{
if (IsValid)
{
var context = new ApplicationDbContext();
var signinUser = context.Users.FirstOrDefault(u => u.UserName == UserName.Text);
if (signinUser!= null && !signinUser.IsDeleted)
{
// Validate the user password
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext())).Authentication;
IdentityResult result = manager.CheckPasswordAndSignIn(Context.GetOwinContext().Authentication, UserName.Text, Password.Text, RememberMe.Checked);
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
FailureText.Text = result.Errors.FirstOrDefault();
ErrorMessage.Visible = true;
}
}
else
{
FailureText.Text = "Please register";
ErrorMessage.Visible = true;
}
}
}
开发者ID:hristo11111,项目名称:TelerikAcademy-HristoBratanov,代码行数:30,代码来源:Login.aspx.cs
示例8: Course
public CourseViewModel Course([FromUri] int ID)
{
using (var ctx = new ApplicationDbContext())
{
return new CourseViewModel(ctx.Courses.Include(m => m.Prerequisites).Single(m => m.ID == ID));
}
}
开发者ID:mgildea,项目名称:CourseAllocation,代码行数:7,代码来源:AdminApiController.cs
示例9: BookRepository
public BookRepository(ApplicationDbContext context, ApplicationUser user) {
if (context == null) throw new ArgumentException(nameof(context));
if (user == null) throw new ArgumentException(nameof(user));
_context = context;
_user = user;
}
开发者ID:chrisdotwood,项目名称:Flip,代码行数:7,代码来源:BookRepository.cs
示例10: doesUserNameExist
public JsonResult doesUserNameExist(string UserName)
{
var db = new ApplicationDbContext();
var user = db.Users.Where(c => c.UserName == UserName).FirstOrDefault();
return Json(user == null);
}
开发者ID:jsraffi,项目名称:osismodelWeb,代码行数:7,代码来源:AccountController.cs
示例11: ButtonEditAnswer_Click
protected void ButtonEditAnswer_Click(object sender, EventArgs e)
{
var text = this.AnswerText.Text;
if (string.IsNullOrWhiteSpace(text) || text == "<br>")
{
ErrorSuccessNotifier.AddErrorMessage("Answer body can't be empty");
return;
}
var answerId = Convert.ToInt32(Request.Params["id"]);
var context = new ApplicationDbContext();
var answer = context.Answers.Find(answerId);
if (answer.Text != text)
{
answer.Text = text;
}
context.SaveChanges();
ErrorSuccessNotifier.ShowAfterRedirect = true;
ErrorSuccessNotifier.AddSuccessMessage("Answer edited");
Response.Redirect("~/QuestionForm.aspx?id=" + answer.Question.Id);
}
开发者ID:nnaidenov,项目名称:GoldstoneForum,代码行数:26,代码来源:EditAnswer.aspx.cs
示例12: Index
//
// GET: /Manage/Index
public async Task<ActionResult> Index(ManageMessageId? message)
{
ApplicationDbContext db = new ApplicationDbContext();
ViewBag.StatusMessage =
message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
: message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
: message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
: message == ManageMessageId.Error ? "An error has occurred."
: message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
: message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
: "";
var userId = User.Identity.GetUserId();
var model = new IndexViewModel
{
HasPassword = HasPassword(),
PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
Logins = await UserManager.GetLoginsAsync(userId),
BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
MinutesBetweenAlerts = db.Users.Single(m => m.UserName == User.Identity.Name).MinutesBetweenAlerts,
};
return View(model);
}
开发者ID:johnnyRose,项目名称:PiSpy,代码行数:29,代码来源:ManageController.cs
示例13: Init
public void Init()
{
_trans = new TransactionScope();
// make connection
db = new ApplicationDbContext();
//make controller
controller = new ReviewController { DbContext = db };
// seed the database if empty
if (db.Members.Count() == 0)
{
new Migrations.Configuration().SeedDebug(db);
Console.WriteLine("Seeded DB");
}
else
{
Console.WriteLine("DB Already seeded");
}
Review validTestReview = new Review();
Game game = db.Games.FirstOrDefault();
Member member = db.Members.FirstOrDefault();
validTestReview.Game_Id = game.Id;
validTestReview.Game = game;
validTestReview.Author = member;
validTestReview.Rating = 3;
validTestReview.Body = "Great Game!";
validTestReview.Subject = "Review Title";
validTestReview.IsApproved = false;
validTestReview.Aprover_Id = null;
db.Reviews.Add(validTestReview);
db.SaveChanges();
}
开发者ID:SeaSharpe,项目名称:Implementation,代码行数:35,代码来源:ReviewControllerTest.cs
示例14: RegisterTest
public void RegisterTest()
{
using (var db = new ApplicationDbContext())
{
//arrange
string password = "joshua";
string email = "[email protected]";
string role = "admin";
string firstname = "Mark Joshua";
string lastname = "Abrenica";
RegisterViewModel registration = new RegisterViewModel()
{
Password = password,
Email = email,
ConfirmPassword = password,
Role = role,
FirstName = firstname,
LastName = lastname
};
//act
AccountController controller = new AccountController();
bool output = controller.RegisterUser(registration);
//assert
Assert.IsTrue(output);
}
}
开发者ID:abrenicamarkjoshua,项目名称:ArchiveSystem,代码行数:29,代码来源:AccountControllerTest.cs
示例15: ClearStatistics
public int ClearStatistics()
{
var context = new ApplicationDbContext();
context.Statistics.RemoveRange(context.Statistics);
context.SaveChanges();
return context.Statistics.Count();
}
开发者ID:da451,项目名称:QuestEngine,代码行数:7,代码来源:AdminService.cs
示例16: EditUserProfile
public ActionResult EditUserProfile(string id)
{
var context = new ApplicationDbContext();
var user = context.Users.Include("Profile").FirstOrDefault(u => u.UserName == id);
this.ViewBag.user = user;
return this.View();
}
开发者ID:AndrewMitev,项目名称:Telerik-Academy,代码行数:7,代码来源:HomeController.cs
示例17: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
ApplicationDbContext db = new ApplicationDbContext();
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = Authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications()
{
// If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
AuthorizationCodeReceived = (context) =>
{
var code = context.Code;
ClientCredential credential = new ClientCredential(clientId, appKey);
string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID));
AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);
return Task.FromResult(0);
}
}
});
}
开发者ID:snowstormlife,项目名称:blizGeekQuiz,代码行数:32,代码来源:Startup.Auth.cs
示例18: Prop
public Prop()
{
//TODO: Get date and lookup to see what Football week is being played
ApplicationDbContext db = new ApplicationDbContext();
var weekId = db.Week.First().Week_Id;
this.Week = weekId;
}
开发者ID:nvolpe,项目名称:HappyBall,代码行数:7,代码来源:Prop.cs
示例19: Insert
public void Insert(string username)
{
using (var rep = new OrderRepository())
{
ApplicationDbContext dbcon = new ApplicationDbContext();
OrderView model = new OrderView();
var obj = new PatientBusiness();
var shop = new ShoppingCartBusiness();
var person = dbcon.Patients.SingleOrDefault(x => x.UserName.Equals(username));
var tot = shop.ComputeTotal(username);
if (tot != 0)
{
if (person != null)
{
model.FirstName = person.FirstName;
model.LastName = person.LastName;
}
model.TotalCost = shop.ComputeTotal(username);
model.Username = username;
rep.Insert(ConvertToProduct(model));
}
ShoppingCartBusiness biz = new ShoppingCartBusiness();
biz.UpdateCheck(username);
}
}
开发者ID:21428432,项目名称:Basic,代码行数:32,代码来源:OrderBusiness.cs
示例20: CallForPapersController
public CallForPapersController(IConferenceService conferenceService, IImageUploader imageUploader, ApplicationDbContext dbContext)
{
_conferenceService = conferenceService;
_imageUploader = imageUploader;
_dbContext = dbContext;
_cfpSpeakerImageContainerName = ConfigurationManager.AppSettings["Storage.Container.CallForPaper.SpeakerImages"];
}
开发者ID:iloabn,项目名称:swetugg-web,代码行数:7,代码来源:CallForPapersController.cs
注:本文中的ApplicationDbContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论