本文整理汇总了C#中DatabaseContext类的典型用法代码示例。如果您正苦于以下问题:C# DatabaseContext类的具体用法?C# DatabaseContext怎么用?C# DatabaseContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseContext类属于命名空间,在下文中一共展示了DatabaseContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update(ContentItem contentItem)
{
using (DatabaseContext context = new DatabaseContext())
{
context.Update<MSSQL.Entities.ContentItem, ContentItem>(contentItem, new string[] { "Id" });
}
}
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Session["New"] != null)
{
int hitchBotId = (int)Session[SessionInfo.HitchBotId];
var skip = Request.QueryString["skip"];
int skipOver = 0;
if (int.TryParse(skip, out skipOver))
{
currentSkip = skipOver;
}
using (var db = new DatabaseContext())
{
var imageList = db.Images.Where(l => !l.TimeDenied.HasValue && l.TimeApproved.HasValue && l.HitchBotId == hitchBotId).OrderByDescending(l => l.TimeTaken).Skip(skipOver).Take(50).ToList();
var master = Master as imageGrid;
master.SetImageSkip(currentSkip);
master.SetImages(imageList);
}
}
else
{
Response.Redirect("Unauthorized.aspx");
}
}
示例3: UserControl_Loaded
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
using (var context = new DatabaseContext())
{
if (AccountNumber != null)
{
var account = context.CustomerAccounts.FirstOrDefault(c => c.AccountNumber == AccountNumber);
if (account != null)
{
var customer = context.Customers.FirstOrDefault(c => c.CustomerID == account.CustomerID);
var territory = context.Territories.FirstOrDefault(c => c.TerritoryID == account.TerritoryID);
var product = context.Products.FirstOrDefault(c => c.ProductID == account.ProductID);
var agent = context.Agents.FirstOrDefault(c => c.AgentId == account.AgentId);
if (customer != null && territory != null && product != null)
{
txtAccountNumber.Text = account.AccountNumber;
txtDiscount.Text = account.Discount;
txtGross.Text = account.Gross;
txtNetValue.Text = account.NetValue;
txtServiceCharge.Text = account.ServiceCharge;
txtCompanyName.Text = customer.CompanyName;
txtModeOfPayment.Text = account.ModeOfPayment;
txtProduct.Text = product.ProductName;
txtTerritory.Text = territory.TerritoryName;
txtAgent.Text = agent.AgentName;
}
}
}
}
}
示例4: QueryValidateUser
private Task<string> QueryValidateUser(string str1, string str2)
{
return Task.Factory.StartNew(() =>
{
try
{
using (var context = new DatabaseContext())
{
var user = context.UserAccounts.FirstOrDefault(c => c.UserAccountId == str1
&& c.Password == str2);
if (user != null)
{
empno = str1;
mainUser = user;
return null;
}
else
{
mainUser = null;
return "Invalid username or password";
}
}
}
catch (Exception ex)
{
return "Error : " + ex.Message;
}
});
}
示例5: GetFiltered
static IQueryable<Journal> GetFiltered(Filter filter, DatabaseContext context)
{
IQueryable<Journal> result = context.Journal;
if (filter.JournalTypes.Any())
result = result.Where(x => filter.JournalTypes.Contains(x.JournalType));
if (filter.ConsumerUIDs.Any())
result = result.Where(x => filter.ConsumerUIDs.Contains(x.ObjectUID));
if (filter.DeviceUIDs.Any())
result = result.Where(x => filter.DeviceUIDs.Contains(x.ObjectUID));
if (filter.UserUIDs.Any())
result = result.Where(x => filter.UserUIDs.Contains(x.UserUID));
if (filter.TariffUIDs.Any())
result = result.Where(x => filter.TariffUIDs.Contains(x.ObjectUID));
result = result.Where(x => x.DateTime > filter.StartDate && x.DateTime < filter.EndDate);
if (filter.IsSortAsc)
result = result.OrderBy(x => x.DateTime);
else
result = result.OrderByDescending(x => x.DateTime);
return result;
}
示例6: LoadEmployees
private void LoadEmployees(string text)
{
using (var context = new DatabaseContext())
{
var employee = context.Employees.ToList();
listEmployees.Items.Clear();
employeesList.Clear();
if (employee != null)
{
foreach (var item in employee)
{
employeesList.Add(new EmployeeView
{
EmployeeName = item.FirstName + " " + item.MiddleName + " " + item.LastName
});
}
}
foreach (var item in employeesList.Where(c => c.EmployeeName.ToLower().Contains(text.ToLower())).ToList())
{
listEmployees.Items.Add(item.EmployeeName);
}
}
}
示例7: DbService
public DbService()
{
Context = new DatabaseContext(DbServiceHelper.CreateConnection());
Context.Database.CommandTimeout = 180;
GKScheduleTranslator = new GKScheduleTranslator(this);
GKDayScheduleTranslator = new GKDayScheduleTranslator(this);
PassJournalTranslator = new PassJournalTranslator(this);
JournalTranslator = new JournalTranslator(this);
AccessTemplateTranslator = new AccessTemplateTranslator(this);
AdditionalColumnTypeTranslator = new AdditionalColumnTypeTranslator(this);
CardTranslator = new CardTranslator(this);
CurrentConsumptionTranslator = new CurrentConsumptionTranslator(this);
DayIntervalTranslator = new DayIntervalTranslator(this);
DepartmentTranslator = new DepartmentTranslator(this);
EmployeeTranslator = new EmployeeTranslator(this);
HolidayTranslator = new HolidayTranslator(this);
NightSettingTranslator = new NightSettingTranslator(this);
OrganisationTranslator = new OrganisationTranslator(this);
PassCardTemplateTranslator = new PassCardTemplateTranslator(this);
PositionTranslator = new PositionTranslator(this);
ScheduleTranslator = new ScheduleTranslator(this);
ScheduleSchemeTranslator = new ScheduleSchemeTranslator(this);
GKCardTranslator = new GKCardTranslator(this);
GKMetadataTranslator = new GKMetadataTranslator(this);
TimeTrackTranslator = new TimeTrackTranslator(this);
TimeTrackDocumentTypeTranslator = new TimeTrackDocumentTypeTranslator(this);
TimeTrackDocumentTranslator = new TimeTrackDocumentTranslator(this);
TestDataGenerator = new TestDataGenerator(this);
ImitatorUserTraslator = new ImitatorUserTraslator(this);
ImitatorScheduleTranslator = new ImitatorScheduleTranslator(this);
ImitatorJournalTranslator = new ImitatorJournalTranslator(this);
}
示例8: LoadProducts
private void LoadProducts(string text)
{
using (var context = new DatabaseContext())
{
var products = context.Products.ToList();
listProducts.Items.Clear();
productsList.Clear();
if (products != null)
{
foreach (var product in products)
{
productsList.Add(new ProductView
{
ProductName = product.ProductName
});
}
}
foreach (var item in productsList.Where(c => c.ProductName.ToLower().Contains(text.ToLower()) && c.ProductName != " ").OrderBy(c => c.ProductID).ToList())
{
listProducts.Items.Add(item.ProductName);
}
}
}
示例9: WizardDialog
public WizardDialog()
{
InitializeComponent();
//New Up DB Object
_db = new DatabaseContext();
}
示例10: CreatePoll
public async Task<IHttpActionResult> CreatePoll(string name)
{
using (var dbContext = new DatabaseContext())
{
if (string.IsNullOrWhiteSpace(name))
return BadRequest().WithReason("A name is required");
var exists = await GetPolls(dbContext, DateTime.Now)
.AnyAsync(p => p.Name == name);
if (exists)
return StatusCode(HttpStatusCode.Conflict)
.WithReason("A poll with the same name already exists");
var currentUser = await dbContext.Users.SingleAsync(u => u.UserName == User.Identity.Name);
var poll = new LunchPoll
{
Name = name,
Date = DateTime.Now,
Voters = new List<User>(),
Votes = new List<LunchVote>()
};
dbContext.LunchPolls.Add(poll);
await AddToPoll(dbContext, poll, currentUser);
await dbContext.SaveChangesAsync();
LunchHub.OnPollChanged(new LunchPollViewModel(poll));
return Ok();
}
}
示例11: GetOptions
public IEnumerable<LunchOption> GetOptions(string q = "")
{
using (var dbContext = new DatabaseContext())
{
return dbContext.LunchOptions.Where(o => o.Name.Contains(q)).ToList();
}
}
示例12: CreateActiveUser
public static UserEntity CreateActiveUser(string email, Role role)
{
using (var context = new DatabaseContext())
{
var passwordManager = new PasswordManager(new Configuration());
var salt = passwordManager.GenerateSalt();
var hashedPassword = passwordManager.HashPassword(Password, salt);
var enctyptedSecurePhrase = passwordManager.EncryptSecurePhrase(Phrase);
var user = new UserEntity
{
Id = Guid.NewGuid(),
Email = email,
FirstName = email,
LastName = email,
Role = role,
UserState = UserState.Activated,
PasswordSalt = salt,
HashedPassword = hashedPassword,
EncryptedSecurePhrase = enctyptedSecurePhrase,
FirstSecurePhraseQuestionCharacterIndex = 0,
SecondSecurePhraseQuestionCharacterIndex = 1,
};
context.Users.Add(user);
context.SaveChanges();
return user;
}
}
示例13: UserControl_Loaded
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
using (var context = new DatabaseContext())
{
var markstrat = new MarketingStrategy();
if (MarketingStrategiesId > 0)
{
var markstarte = context.MarketingStrategies.FirstOrDefault(c => c.MarketingStrategyId == MarketingStrategiesId);
if (markstarte != null)
{
lblMarketingStrategyId.Visibility = Visibility.Visible;
txtMarketingStrategyId.Visibility = Visibility.Visible;
Grid.SetRow(lblMarketingStrategyName, 1);
Grid.SetRow(txtMarketingStrategyName, 1); Grid.SetColumn(txtMarketingStrategyName, 1);
txtMarketingStrategyId.Text = Convert.ToString(markstarte.MarketingStrategyId);
txtMarketingStrategyName.Text = markstarte.Description;
}
}
else
{
lblMarketingStrategyId.Visibility = Visibility.Hidden;
txtMarketingStrategyId.Visibility = Visibility.Hidden;
Grid.SetRow(lblMarketingStrategyName, 0);
Grid.SetRow(txtMarketingStrategyName, 0); Grid.SetColumn(txtMarketingStrategyName, 1);
txtMarketingStrategyName.Text = "";
}
}
}
示例14: Window_Loaded
private void Window_Loaded(object sender, RoutedEventArgs e)
{
using (var context = new DatabaseContext())
{
var lead = context.Leads.FirstOrDefault(c => c.LeadID == LeadId);
var territory = context.Territories.FirstOrDefault(c => c.TerritoryID == lead.TerritoryID);
txtCompanyAddress.Text = lead.CompanyAddress;
txtCompanyName.Text = lead.CompanyName;
txtLeadId.Text = Convert.ToString(lead.LeadID);
txtStatus.Text = lead.Status;
txtTerritory.Text = territory.TerritoryName;
}
#region animation onLoading
double screenWidth = Application.Current.MainWindow.Width;
if (screenLeftEdge > 0 || screenLeftEdge < -8)
{
screenWidth += screenLeftEdge;
}
DoubleAnimation animation = new DoubleAnimation(0, this.Width, (Duration)TimeSpan.FromSeconds(0.3));
DoubleAnimation animation2 = new DoubleAnimation(screenWidth, screenWidth - this.Width, (Duration)TimeSpan.FromSeconds(0.3));
this.BeginAnimation(Window.WidthProperty, animation);
this.BeginAnimation(Window.LeftProperty, animation2);
#endregion
}
示例15: Update
public void Update(Timeline timeline)
{
using (DatabaseContext context = new DatabaseContext())
{
context.Update<MSSQL.Entities.ContentItem, Timeline>(timeline, new string[] { "Id", "Timestamp" });
}
}