protected override void Seed(OnlineStoreContext context) { if (!context.Users.Any(x => x.Role == UserRole.Admin)) { var adminUser = new User { Username = "******", Password = "******", FirstName = "Pesho", LastName = "Bradata", EMail = "[email protected]", Role = UserRole.Admin, Address = new Address() { AddressText = "Server room 1", Town = new Town() { Name = "Plovdiv" } } }; var firstSupplier = new Supplier { Name = "Awful Creatures Ltd.", Phone = "+35929110101", Address = new Address() { AddressText = "Staria Lebed 1", Town = new Town() { Name = "Varna" } } }; context.Users.Add(adminUser); context.Suppliers.Add(firstSupplier); context.SaveChanges(); var demoClient = new User { Username = "******", Password = "******", FirstName = "Mara", LastName = "Hubavicata", EMail = "*****@*****.**", Role = UserRole.Client, ReferalUser = context.Users.First(), Address = new Address() { AddressText = "Carigradsko shose 1", Town = new Town() { Name = "Tutrakan" } } }; context.Users.Add(demoClient); context.SaveChanges(); } }
public void SaveOrder(Order order) { _ctx.AttachRange(order.Lines.Select(l => l.Product)); if (order.OrderID == 0) { _ctx.Orders.Add(order); } _ctx.SaveChanges(); }
private static void DeleteCustomers() { //var customer = _context.Customers.First(c => c.Id == 1); var customer = new Customer { Id = 1 }; _context.Customers.Remove(customer); _context.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,Total,CuponId")] Carrito carrito) { if (ModelState.IsValid) { db.Carrito.Add(carrito); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(carrito)); }
public ActionResult Create([Bind(Include = "Id,Name,Price,DescriptionProduct,Size,Color,Model,Gender")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create([Bind(Include = "Id,Amount,Max,Min,PriceStore,InputId")] Store store) { if (ModelState.IsValid) { db.Stores.Add(store); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.InputId = new SelectList(db.Inputs, "Id", "DateIn", store.InputId); return(View(store)); }
public ActionResult Create([Bind(Include = "Id,Name,Phone,Email,Password,Address,RoleId")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoleId = new SelectList(db.Roles, "Id", "Description", user.RoleId); return(View(user)); }
public ActionResult Create([Bind(Include = "Id,Nombre,Descripcion,Precio,ImageFile,FechaAlta,Existencias,CategoriaId")] Producto producto) { if (ModelState.IsValid) { db.Productos.Add(producto); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoriaId = new SelectList(db.Categorias, "Id", "Nombre", producto.CategoriaId); return(View(producto)); }
public ActionResult Create([Bind(Include = "Id,PriceTotal,Date,Amount,UserId,OutputId")] Sale sale) { if (ModelState.IsValid) { db.Sales.Add(sale); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OutputId = new SelectList(db.Outputs, "Id", "DateOut", sale.OutputId); ViewBag.UserId = new SelectList(db.Users, "Id", "Name", sale.UserId); return(View(sale)); }
private static void InsertProducts() { var bread = new Product() { Name = "Fan", Price = 1500 }; var liquid = new Product[] { new Product { Name = "TV", Price = 30000 }, new Product { Name = "Oven", Price = 10000 } }; using (var context = new OnlineStoreContext()) { context.Products.Add(bread); context.AddRange(liquid); context.SaveChanges(); } }
private static void InsertCustomers() { var customer = new Customer() { Name = "Anna1" }; var customerSet = new Customer[] { new Customer { Name = "Ivan1" }, new Customer { Name = "Pavel1" } }; using (var context = new OnlineStoreContext()) { //context.Customers.Add(customer); context.Add(customer); context.AddRange(customerSet); context.SaveChanges(); } }
public static void Initialize(OnlineStoreContext context) { context.Database.EnsureCreated(); // Look for any students. //if (context.Users.Any()) //{ // return; // DB has been seeded //} var users = new User[] { new User { Name = "Carson", Password = "******" }, new User { Name = "Meredith", Password = "******" }, new User { Name = "Arturo", Password = "******" }, }; context.Users.AddRange(users); context.SaveChanges(); }
private static void InsertCustomers() { var customer = new Customer { Name = "Nikolay" }; using (var context = new OnlineStoreContext()) { context.Customers.Add(customer); context.SaveChanges(); } }
private static void UpdateProductsDisconnected() { var product = new Product { Id = 1, Name = "Test1", Price = 10M - 10M * 0.1M }; using (var newContext = new OnlineStoreContext()) { newContext.Products.Update(product); newContext.SaveChanges(); } }
private static void UpdateCustomersDisconnected() { var product = new Product { Id = 1, Name = "TEST", Price = 10m - 10m * 0.1m }; using (var newContext = new OnlineStoreContext()) { newContext.Products.Update(product); newContext.SaveChanges(); } }
private static void MigrateCategories() { using (var reader = new StreamReader("StaticData/Categories.json")) { var jsonData = reader.ReadToEnd(); var categoryJsonData = JsonConvert.DeserializeObject <IEnumerable <CategoryJsonModel> >(jsonData); var dbCategories = _context.Categories.Select(category => category.SeederId).ToList(); categoryJsonData = categoryJsonData.Where(x => !dbCategories.Contains(x.SeederId)); if (categoryJsonData.Any()) { var categories = categoryJsonData.Select(item => new Category { Name = item.Name, SeederId = item.SeederId }); _context.Categories.AddRange(categories); _context.SaveChanges(); } } }
private static void UpdateProductsDisconnected() { //var product = _context.Products.First(); //product.Price *= 1.1M; var product = new Product() { Id = 1, Name = "Bread", Price = 50M - 50M * 0.1M }; using (var newContext = new OnlineStoreContext()) { newContext.Products.Update(product); newContext.SaveChanges(); } }
private static void InsertProducts() { var product = new Product { Name = "iPhone XsMax", Price = 119990 }; var products = new Product[] { new Product { Name = "Samsung A8", Price = 69990 }, new Product { Name = "Sony XperiaZ", Price = 59990 } }; using (var context = new OnlineStoreContext()) { context.Add(product); context.AddRange(products); context.SaveChanges(); } }
private static void InsertCustomers() { var customer = new Customer { Name = "Alex" }; var customerSet = new Customer[] { new Customer { Name = "Tom" }, new Customer { Name = "John" } }; using (var context = new OnlineStoreContext()) { context.Customers.Add(customer); context.AddRange(customerSet); context.SaveChanges(); } }
private static void InsertProduct() { var product = new Product { Name = "Bread", Price = 10 }; var productSet = new Product[] { new Product { Name = "Milk", Price = 62 }, new Product { Name = "Cheese", Price = 39 } }; using (var context = new OnlineStoreContext()) { context.Products.Add(product); context.Products.AddRange(productSet); context.SaveChanges(); } }
private static void InsertProduct() { var product = new Product { Name = "apple", Price = 30 }; var productSet = new Product[] { new Product { Name = "tomato", Price = 25 }, new Product { Name = "orange", Price = 65 } }; using (var context = new OnlineStoreContext()) { context.Add(product); context.AddRange(productSet); context.SaveChanges(); } }
private static void InsertProduct() { var product = new Product { Name = "Ryazenka", Price = 5 }; var products = new Product[] { new Product { Name = "kefir", Price = 4 }, new Product { Name = "Yogurt", Price = 5 } }; using (var context = new OnlineStoreContext()) { context.Products.Add(product); context.AddRange(products); context.SaveChanges(); } }
public static void Initialize(OnlineStoreContext db) { db.Database.EnsureCreated(); // Проверка занесены ли емкости if (db.GroupGoods.Any() || db.Goods.Any() || db.Courier.Any()) { return; // База данных инициализирована } int group_number = 55; int operations_number = 600; string nameGroup; string descriptionGroup; string descriptionGoods; string nameGoods; string lastName; string firstName; string patronomic; int stockAvailability_value; Random randObj = new Random(1); //Заполнение таблицы группы string[] namesGroup = { "Анаболики_", "Протеин_", "Креатин_", "Витамины_", "Протеиновые_батончики_", "Омега_3_" }; //словарь названий группы товаров string[] descriptionGroupMas = { "Стимуляторы", "Растительный_белок", "Усилитель", "Иммунитет", "Сила", "Укрепление", "Энергия", "Животный белок" }; //словарь описаний продукта int count_Group_voc = namesGroup.GetLength(0); int count_description_voc = descriptionGroupMas.GetLength(0); for (int GroupID = 1; GroupID <= group_number; GroupID++) { nameGroup = namesGroup[randObj.Next(count_Group_voc)] + GroupID.ToString(); descriptionGroup = descriptionGroupMas[randObj.Next(count_description_voc)]; db.GroupGoods.Add(new GroupGoods { NameGroup = nameGroup, DescriptionGroup = descriptionGroup }); } //сохранение изменений в базу данных, связанную с объектом контекста db.SaveChanges(); //Заполнение таблицы товара string[] goods_voc = { "СпортНутришин_", "ЭнергетическийБатончик_Спартак_", "Креатин3000_", "Витаминки_", "Гейнер_", "Гематоген_" }; string[] descriptionGoodsMas = { "Увеличивает_Мыщечную_Массу", "Укрепляет_Имунитет", "Увеличивает_Силу", "Повышается_выносливость", "Сила", "Укрепление_Костей", "Энергия_на_весь_день", "Укрепляет_Тело" };//словарь описаний продукта int[] stockAvailability = { 0, 1 }; int count_goods_voc = goods_voc.GetLength(0); int count_descriptionGoods_voc = descriptionGoodsMas.GetLength(0); int count_stock_voc = descriptionGoodsMas.GetLength(0); for (int fuelID = 1; fuelID <= operations_number; fuelID++) { int GroupID = randObj.Next(1, group_number - 1); nameGoods = goods_voc[randObj.Next(count_goods_voc)] + fuelID.ToString(); descriptionGoods = descriptionGoodsMas[randObj.Next(count_descriptionGoods_voc)] + fuelID.ToString(); stockAvailability_value = stockAvailability[randObj.Next(count_stock_voc)] + fuelID; db.Goods.Add(new Goods { NameGoods = nameGoods, StockAvailability = stockAvailability_value, GroupId = GroupID }); } //сохранение изменений в базу данных, связанную с объектом контекста db.SaveChanges(); string[] LastName = { "Заяц_", "Петрушкин_", "Ястребов_", "Курако_", "Керпеченко_", "Иванов_" }; string[] FirstName = { "Кирилл_", "Александр_", "Алексей_", "Коля_", "Герман_", "Стас_" }; string[] Patronymic = { "Михайлович_", "Олегович_", "Алексеевич_", "Андреевич_", "Дмитриевич_", "Александрович_" }; int count_lastName_voc = LastName.GetLength(0); int count_firstName_voc = FirstName.GetLength(0); int count_Patronymic_voc = Patronymic.GetLength(0); //Заполнение таблицы курьеров for (int operationID = 1; operationID <= group_number; operationID++) { lastName = LastName[randObj.Next(count_lastName_voc)] + operationID.ToString(); firstName = LastName[randObj.Next(count_firstName_voc)] + operationID.ToString(); patronomic = LastName[randObj.Next(count_Patronymic_voc)] + operationID.ToString(); db.Courier.Add(new Courier { LastNameCour = lastName, FirstNameCour = firstName, PatronymicCour = patronomic }); } //сохранение изменений в базу данных, связанную с объектом контекста db.SaveChanges(); }
public int Complete() { return(_context.SaveChanges()); }
public OrderItem Create(OrderItem orderItem) { _dbContext.OrderItems.Add(orderItem); _dbContext.SaveChanges(); return(orderItem); }
public void Commit() { _dbContext.SaveChanges(); }
public void Register(Customer customer) { customer.IsTheAccountActive = true; database.Add(customer); database.SaveChanges(); }
public Customer Create(Customer customer) { _dbContext.Customers.Add(customer); _dbContext.SaveChanges(); return(customer); }
public Category Create(Category category) { _dbContext.Categories.Add(category); _dbContext.SaveChanges(); return(category); }
public Item Create(Item item) { _dbContext.Items.Add(item); _dbContext.SaveChanges(); return(item); }