public void TestEmployeeAdd() { var context = new AppDbContext(); var emp = new Employee { Id=Guid.NewGuid(), Code = "001", FirstName = "ali", LastName = "hassanzade" }; context.Set<Employee>().Add(emp); context.SaveChanges(); }
// Moved to teste stack trace file location internal static void SelectCount() { using (AppDbContext dbContext = new AppDbContext()) { Console.WriteLine(dbContext.Products.Count()); } }
internal static void Add() { using (AppDbContext dbContext = new AppDbContext()) { new AppDbContext.Initializer().AddItems(dbContext); } }
public void Populate() { var c = new AppDbContext(); this.CreatePoll(c); // this.CreateAnswer(c); }
public void SandboxTest() { var context = new AppDbContext(); var c1 = new Choice { Id = 1 }; var c3 = new Choice { Id = 3 }; var freeAnswer = new FreeTextAnswer { Comment = "my comments", QuestionId = 2 }; var multipleAns = new MultipleChoicesAnswer { QuestionId = 1, SelectedChoices = new List<Choice> { c1, c3 } }; var answer = new PollAnswer { AnswerDate = DateTime.Now, PollId = 1, QuestionAnswers = new List<QuestionAnswer> { freeAnswer, multipleAns } }; context.PollAnswers.AddOrUpdate(answer); context.SaveChanges(); }
private static void InitializeAndSeedDb() { try { // Initializes and seeds the database. Database.SetInitializer(new DBInitializer()); //MySql ConnectionString //string connectionString = "server=localhost;user id=root;password=123456;database=ef_db;port=3306"; //MySql ProviderName //string providerName = "MySql.Data.MySqlClient"; //Sql string connectionString = "Data Source=|DataDirectory|APP_DB.sdf"; //Sql string providerName = "System.Data.SqlServerCe.4.0"; //Need to Default Connection Factory //MySql Factory Database.DefaultConnectionFactory = new SqlCeConnectionFactory(providerName, "", connectionString); //by String using (var context = new AppDbContext(connectionString)) { context.Database.Initialize(force: true); } } catch (Exception ex) { throw; } }
public static void CreateTestUsers(AppDbContext context) { var defaultTenant = context.Tenants.Single(t => t.TenancyName == Tenant.DefaultTenantName); context.Users.Add( new User { Tenant = null, //Tenancy owner UserName = "******", Name = "Owner", Surname = "One", EmailAddress = "*****@*****.**", IsEmailConfirmed = true, Password = "******" //123qwe }); context.Users.Add( new User { Tenant = defaultTenant, //A user of tenant1 UserName = "******", Name = "User", Surname = "One", EmailAddress = "*****@*****.**", IsEmailConfirmed = false, Password = "******" //123qwe }); }
// Moved to teste stack trace file location internal static void Delete() { using (AppDbContext dbContext = new AppDbContext()) { dbContext.Products.RemoveRange(dbContext.Products.Take(10).AsEnumerable()); dbContext.SaveChanges(); } }
protected void Page_Load(object sender, EventArgs e) { AppDbContext _db = new AppDbContext(); try { int catgoryId = Convert.ToInt32(Request.QueryString["catgoryId"]); //Get Data From Database var category = _db.Categories.Find(catgoryId); var categoryViewModel = new CategoryViewModel { CategoryId = category.CategoryId, CategoryName = category.Name }; DataTable catDataTable = ConvertHelper.ConvertObjectToDataTable<CategoryViewModel>(categoryViewModel); var productList = _db.Products.ToList().Where(x => x.CategoryId == category.CategoryId).Select(x => new ProductViewModel { ProductId = x.ProductId, ProductName = x.Name, ProductPrice = x.Price }).ToList(); DataTable proDataTable = ConvertHelper.ConvertListObjectToDataTable<ProductViewModel>(productList); // Setting Report Data Source var catReportSource = catDataTable; var proReportSource = proDataTable; ReportDocument catReportDocument = new ReportDocument(); string strCatReportPath = Server.MapPath("~/CrystalReports/crptSubReport.rpt"); //ReportDocument detailsReportDocument = new ReportDocument(); //string strDetailsReportPath = Server.MapPath("~/CrystalReports/crptDetails.rpt"); ////Loading Sub Report //detailsReportDocument.Load(strDetailsReportPath); //detailsReportDocument.SetDataSource(proReportSource); //Loading Report catReportDocument.Load(strCatReportPath); // Setting Report Data Source if (catReportSource != null) catReportDocument.SetDataSource(catReportSource); ReportDocument detailsReportDocument = catReportDocument.Subreports["crptDetails"]; detailsReportDocument.SetDataSource(proReportSource); this.crptSubReport.ReportSource = catReportDocument; //this.crptSubReport.DataBind(); } catch (Exception ex) { var exp = ex; Response.Write(exp); } }
public ActionResult Read(int id) { using (var context = new AppDbContext()) { var user = context.Users.Single(u => u.Id == id); //var user = context.Users.Last(); return View(user); } }
public void TestEnumMetadata() { var context = new AppDbContext(); context.Database.CreateIfNotExists(); //EnumMetadata.Seed(context); //context.SaveChanges(); //var users = context.Set<User>().ToList(); }
private static void InitializeAndSeedDb() { // Initializes and seeds the database. Database.SetInitializer(new DBInitializer()); using (var context = new AppDbContext()) { context.Database.Initialize(force: true); } }
public void TestRemoveEmployeeByIRemovable() { var context = new AppDbContext(); var emp = context.Set<Employee>().First(); emp.Remove(); context.SaveChanges(); }
public static SelectList GetAllGenres(AppDbContext db) { var query = from a in db.Genres orderby a.Name select a; List<Genre> allAuthors = query.ToList(); SelectList list = new SelectList(allAuthors, "GenreID", "Name"); return list; }
public static void AddOrUpdateBookGenre(AppDbContext db, Book book, Genre GenreToAdd) { if (book.Genre == GenreToAdd) //new artist is the same as the original artist { //do nothing } else { book.Genre = GenreToAdd; } }
public static SelectList GetAllAuthors(AppDbContext db) { var query = from a in db.Authors orderby a.LName select a; List<Author> allAuthors = query.ToList(); SelectList list = new SelectList(allAuthors, "AuthorID", "FullName"); return list; }
public async Task<string> GetLongUrl(string shortUrl) { using (var context = new AppDbContext()) { var url = await context.Urls.FirstOrDefaultAsync(s => s.ShortUrl == shortUrl); if (url == null) return string.Empty; return url.FullUrl; } }
public static void AddOrUpdateAuthor(AppDbContext db, Book book, Author AuthorToAdd) { if (book.Author == AuthorToAdd) //new artist is the same as the original artist { //do nothing } else { book.Author = AuthorToAdd; } }
protected override void Dispose(bool disposing) { if (disposing) { if (db != null) { db.Dispose(); db = null; } } base.Dispose(disposing); }
public void UpdateBalance(int accountId, decimal newBalance) { var account = new Account { Id = accountId, CurrentBalance = newBalance }; var context = new AppDbContext(); context.Accounts.Attach(account); context.Entry(account).Property(u => u.CurrentBalance).IsModified = true; context.SaveChanges(); }
protected void Page_Load(object sender, EventArgs e) { AppDbContext _db = new AppDbContext(); try { } catch (Exception) { throw; } }
public static SelectList GetAllAuthorsWithAll(AppDbContext db) { var query = from a in db.Authors orderby a.LName select a; List<Author> allAuthors = query.ToList(); allAuthors.Insert(0, new Author { AuthorID = -1, FName = "All" ,LName = "Authors"}); SelectList list = new SelectList(allAuthors, "AuthorID", "FullName"); return list; }
public static SelectList GetAllGenresWithAll(AppDbContext db) { var query = from a in db.Genres orderby a.Name select a; List<Genre> allAuthors = query.ToList(); allAuthors.Insert(0, new Genre { GenreID = -1, Name = "All Genres" }); SelectList list = new SelectList(allAuthors, "GenreID", "Name"); return list; }
public void Mappings() { MethodInfo method = typeof(DbSet<>).GetMethod("ToList"); var context = new AppDbContext(); foreach (var type in this.GetAllEntityTypes()) { //MethodInfo genericMethod = method.MakeGenericMethod(new[] { type }); //genericMethod.Invoke(null, null); ////dbSet.Take(0).ToList(); ////var dbSet = context.Set(type) as dynamic; ////dbSet.ToList(); context.Employees.Take(0).ToList(); } }
public void Setup() { this.context = new AppDbContext(); this.employeeEF = new EmployeeEF(context); transactionScope = new TransactionScope(); Employee employee1 = new Employee("Luis", "Pacheco", new DateTime(2010, 12, 30)); LoadData(employee1); Employee employee2 = new Employee("Luis", "Quispe", new DateTime(2010, 12, 29)); LoadData(employee2); Employee employee3 = new Employee("Luis", "Tovar", new DateTime(2010, 12, 28)); LoadData(employee3); employeeLoaded = employee1; }
private static void Main() { Console.WriteLine("Initializing..."); Database.SetInitializer(new AppDbContext.Initializer()); using (AppDbContext dbContext = new AppDbContext()) { // Ef is lazy and really only initializes on first query if (!dbContext.Products.Any()) dbContext.SaveChanges(); } Console.WriteLine("Initialized"); Console.WriteLine(); while (true) { Console.Write("[S]elect / Select [N]+1 / [C]ount / [A]dd / [D]elete: _\b"); var k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); switch (k) { case 's': Repository1.Select(); break; case 'n': Repository1.SelectN1(); break; case 'c': Repository1.SelectCount(); break; case 'a': Repository2.Add(); break; case 'd': Repository2.Delete(); break; } if (k == 'q') { break; } Console.WriteLine(); } }
public void RetrieveEntirePollStructure() { var context = new AppDbContext(); var poll = context.Polls.Find(1); var free = context.Questions.OfType<Question>().Where(y => y.Type == QuestionType.FreeText).ToList(); var multiple = context.Questions.OfType<MultipleChoicesQuestion>().Include(c => c.Choices).ToList(); var questions = new List<Question>(); questions.AddRange(free); questions.AddRange(multiple); questions.Sort((x, y) => x.Id.CompareTo(y.Id)); poll.Questions = questions; }
private static void InitializeAndSeedDb() { try { // Initializes and seeds the database. Database.SetInitializer(new DbInitializer()); using (var context = new AppDbContext()) { context.Database.Initialize(force: true); } } catch (Exception ex) { throw; } }
public static void Seed(AppDbContext context) { // Create default AppSetting. var appSettings = new List<AppSetting> { new AppSetting { ApplicationName = ".Net Core App", ApplicationVersion = "1.0.0"} }; appSettings.ForEach(a => context.AppSetting.Add(a)); context.SaveChanges(); // Create default Category. var categories = new List<Category> { new Category { Name = "Fruit"}, new Category { Name = "Cloth"}, new Category { Name = "Car"}, new Category { Name = "Book"}, new Category { Name = "Shoe"}, new Category { Name = "Wipper"}, new Category { Name = "Laptop"}, new Category { Name = "Desktop"}, new Category { Name = "Notebook"}, new Category { Name = "AC"} }; categories.ForEach(c => context.Category.Add(c)); context.SaveChanges(); // Create some products. var products = new List<Product> { new Product { Name="Apple", Price=15, CategoryId=1}, new Product { Name="Mango", Price=20, CategoryId=1}, new Product { Name="Orange", Price=15, CategoryId=1}, new Product { Name="Banana", Price=20, CategoryId=1}, new Product { Name="Licho", Price=15, CategoryId=1}, new Product { Name="Jack Fruit", Price=20, CategoryId=1}, new Product { Name="Toyota", Price=15000, CategoryId=2}, new Product { Name="Nissan", Price=20000, CategoryId=2}, new Product { Name="Tata", Price=50000, CategoryId=2}, new Product { Name="Honda", Price=20000, CategoryId=2}, new Product { Name="Kimi", Price=50000, CategoryId=2}, new Product { Name="Suzuki", Price=20000, CategoryId=2}, new Product { Name="Ferrari", Price=50000, CategoryId=2}, new Product { Name="T Shirt", Price=20000, CategoryId=3}, new Product { Name="Polo Shirt", Price=50000, CategoryId=3}, new Product { Name="Shirt", Price=200, CategoryId=3}, new Product { Name="Panjabi", Price=500, CategoryId=3}, new Product { Name="Fotuya", Price=200, CategoryId=3}, new Product { Name="Shari", Price=500, CategoryId=3}, new Product { Name="Kamij", Price=400, CategoryId=3}, new Product { Name="History", Price=20000, CategoryId=4}, new Product { Name="Fire Out", Price=50000, CategoryId=4}, new Product { Name="Apex", Price=200, CategoryId=5}, new Product { Name="Bata", Price=500, CategoryId=5}, new Product { Name="Acer", Price=200, CategoryId=8}, new Product { Name="Dell", Price=500, CategoryId=8}, new Product { Name="HP", Price=400, CategoryId=8} }; products.ForEach(p => context.Product.Add(p)); context.SaveChanges(); }
public OrderRepository(AppDbContext appDbContext, ShoppingCart shoppingCart) { _appDbContext = appDbContext; _shoppingCart = shoppingCart; }
public CategoryRepository(AppDbContext appDbContext) { this.appDbContext = appDbContext; }
public ImportDetailRepository(AppDbContext context) : base(context) { }
public AccountController(AppDbContext ctx) { _ctx = ctx; _heroService = new HeroRepository(_ctx); }
public MealRepository(AppDbContext appDbContext) { this.appDbContext = appDbContext; }
public SaleController(AppDbContext context) { _admin = new Admin.SaleAdmin(context); }
public DeleteModel(AppDbContext context, RoleManager <IdentityRole> roleManager) { _context = context; _roleManager = roleManager; }
public CounterComponent(AppDbContext _db) { db = _db; }
public BoardGamesService(AppDbContext context, IMemoryCache cache) { this._context = context; this._cache = cache; }
public AdminController(AppDbContext db, UserManager <AppUser> userManager, SignInManager <AppUser> signInManager) { _db = db; _userManager = userManager; _signInManager = signInManager; }
public BlogTagRepository(AppDbContext context) : base(context) { }
public AjaxController(AppDbContext context, UserManager <User> userManager) { _context = context; _userManager = userManager; }
public EmailRepository(AppDbContext context) : base(context) { }
public LoaiXesController(AppDbContext context) { _context = context; }
public CategoryRepository(AppDbContext context) : base(context) { }
public UserHandler(AppDbContext context, IPasswordHashProvider passwordHashProvider, IJwt jwtService) { _context = context; _passwordHashProvider = passwordHashProvider; _jwtService = jwtService; }
public ActivityRuleRepository(AppDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { }
public RoomCodeGenerator(AppDbContext dbContext) { _dbContext = dbContext; }
public TeacherController(AppDbContext context) { _context = context; }
public BooksController(AppDbContext dbContext, UserManager <User> userManager, IHostingEnvironment environment) { _dbContext = dbContext; _userManager = userManager; _environment = environment; }
public OrderRepository(AppDbContext context) { this.context = context; }
public HotelRoomRepository(AppDbContext dbContext) : base(dbContext) { }
public ReviewRepo(AppDbContext appDbContext) { _dbContext = appDbContext; }
public Handler(RoleManager <IdentityRole> roleManager, AppDbContext context) { _roleManager = roleManager; _context = context; }
public TicketController(AppDbContext context, UserManager <AppUser> userManager) { _context = context; _userManager = userManager; }
public CountriesController(AppDbContext context) { _context = context; }
public PlaneManagementController(AppDbContext context) { _context = context; }
public ProjectRepository(AppDbContext context) : base(context) { }
public PerguntaController(AppDbContext context) : base(context) { }
private void CreatePoll(AppDbContext context) { var multiple = new MultipleChoicesQuestion { Type = QuestionType.MultipleChoices, Statement = "multiple choices", CanSelectMultiple = true, Choices = new List<Choice> { new Choice { Text = "11111" }, new Choice { Text = "22222" }, new Choice { Text = "33333" } } }; var freeText = new Question { Statement = "free text", Type = QuestionType.FreeText }; var poll = new Poll { Name = "agora vai", Range = 50, CreationDate = DateTime.Now, ExpirationDate = new DateTime(2020, 01, 01), CreationLocation = new Location { Latitude = 90.0f, Longitude = 50.0f }, Questions = new List<Question> { multiple, freeText }, }; context.Polls.Add(poll); context.SaveChanges(); }
// Constructor public MainPage( ) { InitializeComponent(); myPopup = new Popup() { IsOpen = true, Child = new SplashScreen() }; backroungWorker = new BackgroundWorker(); RunBackgroundWorker(); using(AppDbContext context = new AppDbContext("Data Source='isostore:/AccountAssistantDb.sdf'")) { if(!context.DatabaseExists()) { context.CreateDatabase(); } } if(!IsolatedStorageSettings.ApplicationSettings.Contains("situation")) IsolatedStorageSettings.ApplicationSettings.Add("situation", true); if(!IsolatedStorageSettings.ApplicationSettings.Contains("TilePerson")) IsolatedStorageSettings.ApplicationSettings.Add("TilePerson", ""); if(!IsolatedStorageSettings.ApplicationSettings.Contains("TileSituation")) IsolatedStorageSettings.ApplicationSettings.Add("TileSituation", ""); }