public List<Product> getAll() { var prod = new Product() { itemnumber = 1, name = "Tullball", description = "Hei", price = 123, producerid = 2, producer = "Ringnes" }; var prod1 = new Product() { itemnumber = 2, name = "Truse", description = "Hei", price = 23, producerid = 3, producer = "Fjellbekk" }; var prod2 = new Product() { itemnumber = 3, name = "Bjelleklang", description = "Hei", price = 433, producerid = 4, producer = "Brokkoliekspressen" }; var prod3 = new Product() { itemnumber = 4, name = "Bremse", description = "Hei", price = 988, producerid = 6, producer = "Batman" }; var prod4 = new Product() { itemnumber = 5, name = "Apekatt", description = "Hei", price = 900, producerid = 13, producer = "Robin" }; List<Product> productlist = new List<Product>(); productlist.Add(prod); productlist.Add(prod1); productlist.Add(prod2); productlist.Add(prod3); productlist.Add(prod4); return productlist; }
public List<Product> getResult( string searchstring) { var prod = new Product() { itemnumber = 1, name = "Tullball", description = "Hei" }; List<Product> productlist = new List<Product>(); productlist.Add(prod); return productlist; }
public bool AddProduct(string Name, double Price, int Stock, string Description, int CategoryId) { var db = new TankshopDbContext(); var newProduct = new Nettbutikk.Model.Product() { Name = Name, Price = Price, Stock = Stock, Description = Description, CategoryId = CategoryId }; try { db.Products.Add(newProduct); db.SaveChanges(); return true; } catch (Exception e) { LogHandler.WriteToLog(e); } return false; }
public Product addProduct(int id, Product p) { return _product.addProduct(id,p); }
public bool updateProduct(int id,Product p) { return _product.updateProduct(id,p); }
public ActionResult ProductDetails(int id,ProductDetail p) { if (!isAdmin()) { return RedirectToAction("LogIn", "Main"); } if (ModelState.IsValid) { Product updated = new Product() { itemnumber = p.itemnumber, name = p.name, description = p.description, longDescription = p.longDescription, price = p.price, countryid = p.countryid, subCategoryid = p.subCategoryid, volum = p.volum, producerid = p.producerid }; Customer admin = (Customer)Session["loggedInUser"]; var adminid = admin.id; bool result = _product.updateProduct(adminid, updated); List<GroupedSelectListItem> test2 = new List<GroupedSelectListItem>(); var test1 = _product.getAllSubCategories(); foreach (var item in test1) { if (item.ID == p.subCategoryid) { test2.Add(new GroupedSelectListItem() { GroupKey = item.catId.ToString(), GroupName = item.catName, Text = item.name, Value = item.ID.ToString(), Selected = true }); } else { test2.Add(new GroupedSelectListItem() { GroupKey = item.catId.ToString(), GroupName = item.catName, Text = item.name, Value = item.ID.ToString() }); } } IEnumerable<GroupedSelectListItem> test = test2; p.countryList = _product.getCountries().Select(c => new SelectListItem { Value = c.id.ToString(), Text = c.name }).ToList(); p.subCategoryList = test; p.producerList = _product.getProducers().Select(r => new SelectListItem { Value = r.id.ToString(), Text = r.name }).ToList(); if (result) return Json(new { success = true, message = "Endringene ble lagret", redirect = "/Product/ListProducts/" }); return Json(new { success = false, message = "Noe gikk galt, prøv igjen" }); } return Json(new { success = false, message = "Feil i validering" }); }
public Product findProduct(int id) { var product = new Product(); if(id == 1) { product = new Product() { itemnumber = 1, name = "Tullball", description = "Hei", price = 123, volum = 50, producerid = 2, longDescription = "Tullball er et fantastisk godt drikkeprodukt", subCategoryid = 3, countryid = 1 }; } else if (id == 2) { product = new Product() { itemnumber = 2, name = "Tullball", description = "Hei", price = 123, volum = 50, producerid = 2, longDescription = "Tullball er et fantastisk godt drikkeprodukt", subCategoryid = 3, countryid = 1 }; } else { product = new Product() { itemnumber = 1, name = "Tullball", description = "Hei", price = 123, volum = 50, producerid = 2, longDescription = "Tullball er et fantastisk godt drikkeprodukt", subCategoryid = 3, countryid = 1 }; } return product; }
public Product addProduct(int id, Product p) { Product prod = new Product() { name = "Apekatt", description = "Hei", price = 900, producerid = 13, producer = "Robin" }; return prod; }
public Product deleteProduct(int id) { var product = new Product() { itemnumber = 1, name = "dfsdf", description = " dfsfsf" }; return product; }
public bool updateProduct(int id, Product p) { if (id == 0) return false; return true; }
public Product addProduct(int id, Product p) { try { var db = new DatabaseContext(); var newp = new Products() { Name = p.name, Description = p.description, LongDescription = p.longDescription, CountriesId = p.countryid, SubCategoriesId = p.subCategoryid, Price = p.price, Volum = p.volum, ProducersId = p.producerid }; db.Products.Add(newp); db.SaveChanges(id); p.itemnumber = newp.Id; return p; } catch(Exception e) { writeToFile(e); return null; } }
public bool updateProduct(int id,Product update) { var db = new DatabaseContext(); try { Products existing = db.Products.FirstOrDefault(u => u.Id == update.itemnumber); existing.Name = update.name; existing.Price = update.price; existing.Volum = update.volum; existing.SubCategoriesId = update.subCategoryid; existing.ProducersId = update.producerid; existing.CountriesId = update.countryid; existing.Description = update.description; existing.LongDescription = update.longDescription; existing.ProducersId = update.producerid; db.SaveChanges(id); return true; } catch(Exception e) { writeToFile(e); return false; } }