private void SeedEquipment(BrefiContext context) { Brend brend1 = new Brend() { Name = "brend1", BriefInfo = "info1", UpdateTime = new DateTime(2018, 12, 10, 18, 30, 25), IsDeleted = false }; Brend brend2 = new Brend() { Name = "brend2", BriefInfo = "info2", UpdateTime = new DateTime(2018, 12, 10, 18, 30, 25), IsDeleted = false }; context.Brends.AddOrUpdate(x => x.Id, brend1); context.Brends.AddOrUpdate(x => x.Id, brend2); Equipment equipment1 = new Equipment() { Brend = brend1, Price = 12, ToolTypeId = 1, Description = "description 1", UpdateTime = new DateTime(2018, 12, 10, 18, 30, 25), IsDeleted = false }; Equipment equipment2 = new Equipment() { Brend = brend2, Price = 555, ToolTypeId = 2, Description = "description 2", UpdateTime = new DateTime(2018, 12, 10, 18, 30, 25), IsDeleted = false }; context.Equipments.AddOrUpdate(x => x.Id, equipment1); context.Equipments.AddOrUpdate(x => x.Id, equipment2); }
public async Task <IActionResult> Edit(int id, [Bind("BrendID,Naziv")] Brend brend) { if (id != brend.BrendID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(brend); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BrendExists(brend.BrendID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(brend)); }
public ActionResult DeleteConfirmed(int id) { Brend brend = db.Brends.Find(id); db.Brends.Remove(brend); db.SaveChanges(); return(RedirectToAction("Index")); }
public void AddOrUpdateFromDataGrid(Brend brend) { brend.UpdateTime = DateTime.Now; if (brend.Id == 0) { db.Brends.Add(brend); } db.SaveChanges(); }
public async Task <IActionResult> Create([Bind("BrendID,Naziv")] Brend brend) { if (ModelState.IsValid) { _context.Add(brend); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(brend)); }
public int GetNumberOfTradeMark(Brend brend) { int sum = 0; foreach (var product in products) { if (product.Brend == brend) { sum++; } } return(sum); }
// GET: Admin/Brends/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Brend brend = db.Brends.Find(id); if (brend == null) { return(HttpNotFound()); } return(View(brend)); }
private void ADD_Click(object sender, RoutedEventArgs e) { try { //по нажатию кнопки добавляеися товар MContext mc = new MContext(); Brend b = CBBrend.SelectedItem as Brend; Subcategory s = CBSubcategory.SelectedItem as Subcategory; SKU sku = new SKU() { ID_Brend = b.ID, ID_Subcategory = s.ID, Enable = true, idAllo = Allo.Text, idComfy = Comfy.Text, idEldorado = Eldorado.Text, idRozetka = Rozetka.Text, InputPrice = double.Parse(TBInputPrice.Text), Name = TBTitle.Text, Price = int.Parse(TBPrice.Text), UrlHotline = Hotline.Text }; mc.SKUs.Add(sku); mc.SaveChanges(); SkuAnot sa = new SkuAnot() { ID = sku.ID, Val1 = Value1.Text, Val2 = Value2.Text, Val3 = Value3.Text, Val4 = Value4.Text, Val5 = Value5.Text, Val6 = Value6.Text, Val7 = Value7.Text, Val8 = Value8.Text, Val9 = Value9.Text, Val10 = Value10.Text, Val11 = Value11.Text, Val12 = Value12.Text }; mc.SAs.Add(sa); mc.SaveChanges(); MessageBox.Show("Товар успешно добавлен"); this.Close(); } catch { MessageBox.Show("Неверно заполнено поле"); } }
private void ADD_Click(object sender, RoutedEventArgs e) { if (this.Title == "Категорию") { //в зависимотси от того что пришло в конструкторе добавляет или категорию или бренд MContext mc = new MContext(); if (mc.Categories.Any(x => x.Name == AddItems.Text)) { MessageBox.Show(string.Format("Категория {0} уже существует", AddItems.Text)); AddItems.Text = string.Empty; AddItems.Focus(); } else { Category c = new Category() { Name = AddItems.Text }; mc.Categories.Add(c); mc.SaveChanges(); MessageBox.Show(string.Format("Категория {0} успешно добавленна", AddItems.Text)); this.Close(); } } else { MContext mc = new MContext(); if (mc.Brends.Any(x => x.Name == AddItems.Text)) { MessageBox.Show(string.Format("Бренд {0} уже существует", AddItems.Text)); AddItems.Text = string.Empty; AddItems.Focus(); } else { Brend c = new Brend() { Name = AddItems.Text }; mc.Brends.Add(c); mc.SaveChanges(); MessageBox.Show(string.Format("Бренд {0} успешно добавленна", AddItems.Text)); this.Close(); } } }
public static void Seed2(IServiceProvider services) { using (var scope = services.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var manager = scope.ServiceProvider.GetRequiredService <UserManager <User> >(); var managerRole = scope.ServiceProvider.GetRequiredService <RoleManager <Role> >(); var context = scope.ServiceProvider.GetRequiredService <EFContext>(); Brend brend = new Brend { BrendName = "Gachi Muchi" }; Brend brend1 = new Brend { BrendName = "Converse" }; Brend brend2 = new Brend { BrendName = "Anime" }; context.Brend.Add(brend); context.Brend.Add(brend1); context.Brend.Add(brend2); Trend trend = new Trend { TrendName = "Retro Trainers" }; context.Trend.Add(trend); Category category = new Category { CategName = "Man" }; Category category1 = new Category { CategName = "Woman" }; Category category2 = new Category { CategName = "Kids" }; context.Category.Add(category); context.Category.Add(category1); context.Category.Add(category2); context.SaveChanges(); } }
public void AddOrUpdate(Brend brend) { var findBrend = db.Brends.Where(x => x.Id == brend.Id).FirstOrDefault(); if (findBrend != null) { findBrend.Name = brend.Name; findBrend.BriefInfo = brend.BriefInfo; findBrend.UpdateTime = brend.UpdateTime; findBrend.IsDeleted = brend.IsDeleted; } else { db.Brends.Add(brend); } db.SaveChanges(); }
private void Save_Click(object sender, RoutedEventArgs e) { try { MContext mc = new MContext(); Brend b = CBBrend.SelectedItem as Brend; Subcategory s = CBSubcategory.SelectedItem as Subcategory; SKU savesku = mc.SKUs.First(x => x.ID == sk.ID); savesku.ID_Brend = b.ID; savesku.ID_Subcategory = s.ID; savesku.Enable = true; savesku.idAllo = Allo.Text; savesku.idComfy = Comfy.Text; savesku.idEldorado = Eldorado.Text; savesku.idRozetka = Rozetka.Text; savesku.InputPrice = double.Parse(TBInputPrice.Text); savesku.Name = TBTitle.Text; savesku.Price = int.Parse(TBPrice.Text); savesku.UrlHotline = Hotline.Text; mc.SaveChanges(); SkuAnot sa = mc.SAs.First(x => x.ID == savesku.ID); sa.Val1 = Value1.Text; sa.Val2 = Value2.Text; sa.Val3 = Value3.Text; sa.Val4 = Value4.Text; sa.Val5 = Value5.Text; sa.Val6 = Value6.Text; sa.Val7 = Value7.Text; sa.Val8 = Value8.Text; sa.Val9 = Value9.Text; sa.Val10 = Value10.Text; sa.Val11 = Value11.Text; sa.Val12 = Value12.Text; mc.SaveChanges(); MessageBox.Show("Товар успешно изменен"); this.Close(); } catch { MessageBox.Show("Неверно заполнено поле"); } }
public ActionResult Create([Bind(Include = "id,BrendImg")] Brend brend, HttpPostedFileBase Photo) { if (ModelState.IsValid) { if (Photo != null) { WebImage image = new WebImage(Photo.InputStream); FileInfo photoInfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoInfo.Extension; image.Save("~/Uploads/Brands/" + newPhoto); brend.BrendImg = "/Uploads/Brands/" + newPhoto; } db.Brends.Add(brend); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brend)); }
public ActionResult Edit(int id, [Bind(Include = "id,BrendImg")] Brend brend, HttpPostedFileBase Photo) { if (ModelState.IsValid) { Brend selected = db.Brends.SingleOrDefault(br => br.id == id); if (Photo != null) { WebImage image = new WebImage(Photo.InputStream); FileInfo photoinfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoinfo; image.Save("~/Uploads/Brands/" + newPhoto); brend.BrendImg = "/Uploads/Brands/" + newPhoto; } selected.BrendImg = brend.BrendImg; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brend)); }
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { try { comboBox3.Items.Clear(); var val = comboBox2.SelectedItem.ToString(); brend = db.Brends.Where(br => br.Name == val).Where(nm => nm.CategoryId == category.Id).Include(p => p.Products).FirstOrDefault(); foreach (var comB in brend.Products) { comboBox3.Items.Add(comB.Model.ToString()); } comboBox3.Text = ""; } catch (Exception) { MessageBox.Show("Проблема соединения с базой данных. \n Программа будет работать в режиме Offline. ", "Сообщение", MessageBoxButtons.OK); } }
private void UpDateDataBase() { try { decimal price; string pattern = @"[0-9]{10}\,\d{2}"; if (Regex.IsMatch(textBox2.Text, pattern, RegexOptions.IgnoreCase)) { price = decimal.Parse(textBox2.Text); } else { price = decimal.Parse(textBox2.Text.Replace('.', ',').Trim()); } if (checkBox1.Checked == true) { if (db.Categorys.Where(cat => cat.Name == textBox3.Text).Count() == 0) { Category category = new Category { Name = textBox3.Text }; db.Categorys.Add(category); db.SaveChanges(); } categ = db.Categorys.Where(cat => cat.Name == textBox3.Text).FirstOrDefault().Id; } else { categ = category.Id; } if (checkBox2.Checked == true) { if (db.Brends.Where(bre => bre.Name == textBox4.Text) .Where(ctg => ctg.CategoryId == categ).Count() == 0) { Brend brend = new Brend { Name = textBox4.Text, CategoryId = categ }; db.Brends.Add(brend); db.SaveChanges(); } breCat = db.Brends.Where(br => br.Name == textBox4.Text) .Where(ctg => ctg.CategoryId == categ).FirstOrDefault().Id; } else { breCat = brend.Id; } if (checkBox3.Checked == true) { if (db.Products.Where(cat => cat.Model == textBox5.Text) .Where(ctg => ctg.BrendId == breCat).Count() == 0) { Product product = new Product { Model = textBox5.Text, BrendId = breCat, Price = price, Country = textBox1.Text }; db.Products.Add(product); db.SaveChanges(); } prod = db.Products.Where(pr => pr.Model == textBox5.Text) .Where(ctg => ctg.BrendId == breCat).FirstOrDefault().Id; } else { prod = product.Id; } if (dataGridView1.Rows.Count > 1) { if (checkBox1.Checked == true || checkBox2.Checked == true || checkBox3.Checked == true) { for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { Option option = new Option { Name = dataGridView1.Rows[i].Cells[0].Value.ToString(), Value = dataGridView1.Rows[i].Cells[1].Value.ToString(), ProductId = prod }; db.Options.Add(option); db.SaveChanges(); } } if (checkBox1.Checked == false && checkBox2.Checked == false && checkBox3.Checked == false) { var option = db.Options.Where(op => op.ProductId == prod).ToList(); db.Options.RemoveRange(option); db.SaveChanges(); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { Option optionCreate = new Option { Name = dataGridView1.Rows[i].Cells[0].Value.ToString(), Value = dataGridView1.Rows[i].Cells[1].Value.ToString(), ProductId = prod }; db.Options.Add(optionCreate); db.SaveChanges(); } product.Price = price; product.Country = textBox1.Text; db.SaveChanges(); } } } catch (Exception e) { MessageBox.Show("Ошибка в заполнение полей!\n" + e, "Сообщение об ошибке!"); } }
private void ShowSKUs_Click(object sender, RoutedEventArgs e) { MContext mc = new MContext(); List <MyGridMainMenu> lsku = null; if (CBCategory.SelectedIndex == -1) { lsku = mc.SKUs.Select(x => new MyGridMainMenu { ID = x.ID, Категория = x.Subcategory.Category.Name, Подкатегория = x.Subcategory.Name, Бренд = x.Brend.Name, Модель = x.Name, Вход = x.InputPrice, озница = x.Price, Наценка = Math.Round(((x.Price / x.InputPrice) - 1) * 100, 2), Наличие = x.Enable }).ToList(); } else if (CBSubcategory.SelectedIndex == -1) { Category c = CBCategory.SelectedItem as Category; lsku = mc.SKUs.Where(x => x.Subcategory.ID_Category == c.ID).Select(x => new MyGridMainMenu { ID = x.ID, Категория = x.Subcategory.Category.Name, Подкатегория = x.Subcategory.Name, Бренд = x.Brend.Name, Модель = x.Name, Вход = x.InputPrice, озница = x.Price, Наценка = Math.Round(((x.Price / x.InputPrice) - 1) * 100, 2), Наличие = x.Enable }).ToList(); } else if (CBBrend.SelectedIndex == -1) { Subcategory s = CBSubcategory.SelectedItem as Subcategory; lsku = mc.SKUs.Where(x => x.ID_Subcategory == s.ID).Select(x => new MyGridMainMenu { ID = x.ID, Категория = x.Subcategory.Category.Name, Подкатегория = x.Subcategory.Name, Бренд = x.Brend.Name, Модель = x.Name, Вход = x.InputPrice, озница = x.Price, Наценка = Math.Round(((x.Price / x.InputPrice) - 1) * 100, 2), Наличие = x.Enable }).ToList(); } else { Subcategory s = CBSubcategory.SelectedItem as Subcategory; Brend b = CBBrend.SelectedItem as Brend; lsku = mc.SKUs.Where(x => x.ID_Subcategory == s.ID && x.ID_Brend == b.ID).Select(x => new MyGridMainMenu { ID = x.ID, Категория = x.Subcategory.Category.Name, Подкатегория = x.Subcategory.Name, Бренд = x.Brend.Name, Модель = x.Name, Вход = x.InputPrice, озница = x.Price, Наценка = Math.Round(((x.Price / x.InputPrice) - 1) * 100, 2), Наличие = x.Enable }).ToList(); } //предусмотреть варианты не выбранных крмбобоксов if (lsku != null) { DGS.ItemsSource = lsku; } }
public Product(int price, string name, Brend brend) { Price = price; Name = name; Brend = brend; }
public TradeMarkOffer(Brend brend, int numberOfExtraPoints, DateTime expirationDate) { Brend = brend; NumberOfExtraPoints = numberOfExtraPoints; ExpirationDate = expirationDate; }
public TradeMarkOffer(Brend brend, int numberOfExtraPoints) { Brend = brend; NumberOfExtraPoints = numberOfExtraPoints; ExpirationDate = new DateTime(2021, 2, 1, 12, 12, 12); }