public static void deleteAllProducts() { using (ECommerceDBEntities dbEntity = new ECommerceDBEntities()) { dbEntity.Database.ExecuteSqlCommand("TRUNCATE TABLE [T_Product]"); } }
public static void addProducts(List <ProductModel> pmList) { using (ECommerceDBEntities dbEntity = new ECommerceDBEntities()) { var productList = convertToProduct(pmList); dbEntity.T_Product.AddRange(productList); dbEntity.SaveChanges(); } }
public ActionResult YeniUrun(UrunEkleModel model) { ECommerceDBEntities db = new ECommerceDBEntities(); Product productModel = new Product(); productModel.Name = model.ProductName; productModel.SupplierID = model.SupplierID; productModel.CategoryID = model.CategoryID; productModel.SubCategoryID = model.SubCategoryID; productModel.QuantityPerUnit = model.QuantityPerUnit; productModel.UnitPrice = Convert.ToDecimal(model.UnitPrice); productModel.Discount = Convert.ToDecimal(model.Discount); productModel.AltText = model.AltText; productModel.ShortDescription = model.ShortDescription; productModel.LongDescription = model.LongDescription; productModel.UnitsInStock = model.UnitsInStock; if (model.ImageUrl != null && model.ImageUrl.ContentLength > 0) { bool durum = false; foreach (var item in db.Products.ToList()) { if (item.Name.ToLower() == model.ProductName.ToLower()) { durum = true; break; } } if (durum == false) { if (model.SubCategoryID == 1) { model.ImageUrl.SaveAs(Server.MapPath("~/images/aksiyon/" + model.ImageUrl.FileName)); productModel.ImageUrl = "~/images/aksiyon/" + model.ImageUrl.FileName; } else if (model.SubCategoryID == 2) { model.ImageUrl.SaveAs(Server.MapPath("~/images/bilimkurgu/" + model.ImageUrl.FileName)); productModel.ImageUrl = "~/images/bilimkurgu/" + model.ImageUrl.FileName; } else if (model.SubCategoryID == 3) { model.ImageUrl.SaveAs(Server.MapPath("~/images/dram/" + model.ImageUrl.FileName)); productModel.ImageUrl = "~/images/dram/" + model.ImageUrl.FileName; } db.Products.Add(productModel); db.SaveChanges(); } } return(RedirectToAction("Urunler", "Admin")); }
private UrunEkleModel GetModel() { UrunEkleModel model = new UrunEkleModel(); ECommerceDBEntities db = new ECommerceDBEntities(); model.SubCategoryList = (from subC in db.SubCategories select new SelectListItem { Selected = false, Text = subC.Name, Value = subC.SubCategoryID.ToString() }).ToList(); model.SupplierIDList = (from sup in db.Suppliers select new SelectListItem { Selected = false, Text = sup.SuppliersID.ToString(), Value = sup.SuppliersID.ToString() }).ToList(); model.CategoryIDList = (from cat in db.Categories select new SelectListItem { Selected = false, Text = cat.CategoryID.ToString(), Value = cat.CategoryID.ToString() }).ToList(); model.SubCategoryList.Insert(0, new SelectListItem { Selected = true, Value = "", Text = "..Seçiniz.." }); model.SupplierIDList.Insert(0, new SelectListItem { Selected = true, Value = "", Text = "..Seçiniz.." }); model.CategoryIDList.Insert(0, new SelectListItem { Selected = true, Value = "", Text = "..Seçiniz.." }); return(model); }
public static List <ProductModel> getProducts() { List <ProductModel> productList = new List <ProductModel>(); using (ECommerceDBEntities dbEntity = new ECommerceDBEntities()) { var products = (from p in dbEntity.T_Product orderby(p.date) descending select p).ToList(); foreach (var product in products) { ProductModel pm = new ProductModel(); pm.id = product.id; pm.companyName = product.companyName; pm.name = product.name; pm.price = product.price; pm.date = product.date; productList.Add(pm); } } return(productList); }