public ActionResult Create([Bind(Include = "Id,Name,ModelOrSize,Price,ProdImageURL,Brand,Gender,OtherDetails,Country,Quantity,InPromotion")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
private void button1_Click(object sender, EventArgs e) { string productName = txtProduct.Text; string price = txtPrice.Text; string Amount = txtAmount.Text; string category = cmbCategory.Text; string size = cmbSize.Text; string desc = rcDescription.Text; string[] emp = { productName, price, Amount, category, size }; if (mainExtensions.IsEmpty(emp, string.Empty)) { int catId = db.Categories.First(ct => ct.Name == category).Id; int sizeId = db.ProductSizes.First(ct => ct.Size == size).Id; db.Products.Add(new Product() { ProductName = productName, Price = Convert.ToDouble(price), Amount = Convert.ToInt32(Amount), CategoryId = catId, SizeId = sizeId, Description = desc }); db.SaveChanges(); MessageBox.Show("Product create succesfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public RegisteredProduct RegisterProduct(CreateProducto newProducto) { var product = new Product() { CategoryId = newProducto.CategoryId, Name = newProducto.Name, Descripcion = newProducto.Descripcion }; using (var db = new ShopDb()) { if (db.Products.Where(x => x.Name.Equals(product.Name)).Any()) { throw new Exception("No se pueden registrar Productos con el mismo nombre"); } db.Products.Add(product); db.SaveChanges(); return(new RegisteredProduct() { Id = product.Id, CategoryName = db.Categories.Find(product.CategoryId).Name, Description = product.Descripcion, Name = product.Name }); } }
private static void AddItem(ShopDb db, string name, decimal price) { db .Items .Add(new Item { Name = name, Price = price }); db.SaveChanges(); }
private static void RegisterCustomer(ShopDb db, string[] commandInfo) { var customerName = commandInfo[1]; var salesmanId = int.Parse(commandInfo[2]); db.Customers.Add(new Customer { Name = customerName, SalesmanId = salesmanId }); db.SaveChanges(); }
public void AddToCard(Car car) { _dbshop.ShopCartItems.Add(new ShopCartItem { ShopCardId = ShopCardId, car = car, price = car.Price, }); _dbshop.SaveChanges(); }
private static void LeaveReview(ShopDb db, string[] commandInfo) { var customerId = int.Parse(commandInfo[1]); var itemId = int.Parse(commandInfo[2]); db .Reviews .Add(new Review { CustomerId = customerId, ItemId = itemId }); db.SaveChanges(); }
private static void SaveSalesmen(ShopDb db) { var names = Console.ReadLine() .Split(new[] { ';', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var name in names) { db.Salesmans.Add(new Salesman { Name = name }); } db.SaveChanges(); }
public void CategoryInsertionTest() { using (var db = new ShopDb()) { Category newCatery = new Category() { Name = "Frutas", Description = "Vegetales dulces" }; db.Categories.Add(newCatery); db.SaveChanges(); Assert.IsTrue(newCatery.Id > 0); } }
public void CreateOrder(Order order) { order.OrderTime = DateTime.Now; _shopDb.Orders.Add(order); var items = _shopCart.Listshopcartitems; foreach (var item in items) { var orderDetail = new OrderDetail() { CarId = item.car.Id, OrderId = order.Id, Price = item.car.Price }; _shopDb.OrderDetails.Add(orderDetail); } _shopDb.SaveChanges(); }
private static void MakeOrder(ShopDb db, string[] commandInfo) { var customerId = int.Parse(commandInfo[1]); var order = new Order { CustomerId = customerId }; for (int i = 2; i < commandInfo.Length; i++) { order.Items.Add(new ItemOrder { ItemId = int.Parse(commandInfo[i]) }); } db .Orders .Add(order); db.SaveChanges(); }
private void btnRegister_Click(object sender, EventArgs e) { string fullname = txtFullname.Text; string email = txtEmail.Text; string phone = txtPhone.Text; string password = txtPassword.Text; string confirmpas = txtConfirm.Text; string[] myempty = { fullname, email, password, confirmpas }; if (mainExtensions.IsEmpty(myempty, "")) { if (password == confirmpas) { //Worker newWorker = new Worker(); //newWorker.Fullname = fullname; //newWorker.Email = email; //newWorker.Password = password; //newWorker.Phone = phone; db.Workers.Add(new Worker() { Fullname = fullname, Email = email, Password = password, Phone = phone }); db.SaveChanges(); MessageBox.Show("Worker create succesfully"); } else { lblError.Text = "Password and confirm password must be write"; lblError.Visible = true; } } else { } }
public RegisteredProduct RegisterProduct(CreateProducto newProducto) { var product = new Product() { CategoryId = newProducto.CategoryId, Name = newProducto.Name, Descripcion = newProducto.Descripcion }; using (var db = new ShopDb()) { db.Products.Add(product); db.SaveChanges(); return(new RegisteredProduct() { Id = product.Id, CategoryName = db.Categories.Find(product.CategoryId).Name, Description = product.Descripcion, Name = product.Name }); } }
static void Main(string[] args) { using (var db = new ShopDb()) { SalesTurn turn = new SalesTurn() { Active = true, Start = DateTime.Now, End = DateTime.Now, Employees = new HashSet <Employe>() { new Employe() { Address = "Av La Marina 766", Birthday = DateTime.Now.ToString(), Nombre = "Daniel Carbajal", Sex = Sex.Male, } } }; db.SalesTurns.Add(turn); db.SaveChanges(); } }