public ActionResult CreateProduct(Tproduct pvm, HttpPostedFileBase imgfile) { List <Tcategory> list = db.Tcategory.ToList(); ViewBag.categorylist = new SelectList(list, "category_id", "category_name"); string path = uploadimgfile(imgfile); if (path.Equals("-1")) { ViewBag.error = "Image couldnt upload"; } else { Tproduct product = new Tproduct(); product.product_name = pvm.product_name; product.product_price = pvm.product_price; product.product_image = path; product.product_fk_category = pvm.product_fk_category; product.product_des = pvm.product_des; if (Session["Tuser_id"] != null) { product.product_fk_user = Convert.ToInt32(Session["Tuser_id"].ToString()); } db.Tproduct.Add(product); db.SaveChanges(); Response.Redirect("index"); } return(View()); }
public ActionResult SaveProduct(CreateNewProductViewModel saveDto) { try { using (var dbContext = new TicketCodeTestDBContext()) { var efProduct = new Tproduct(); efProduct.Id = UniqueGenerator.UniId(); efProduct.Name = saveDto.productname; efProduct.Title = saveDto.title; efProduct.Class1 = saveDto.class1; efProduct.Class2 = saveDto.class2; efProduct.DeliveryArea = saveDto.deliveryarea; efProduct.SupplierId = saveDto.supplier; efProduct.Cost = saveDto.cost; efProduct.SalePrice = saveDto.saleprice; efProduct.AvailableStock = saveDto.avaliablestock; efProduct.Description = saveDto.description; dbContext.Tproduct.Add(efProduct); dbContext.SaveChanges(); } return(Json(new { success = true })); } catch (Exception ex) { return(Json(new { success = false, msg = ex.ToString() })); } }
public ActionResult DeleteProduct(int?id) { Tproduct product = db.Tproduct.Where(x => x.product_id == id).SingleOrDefault(); db.Tproduct.Remove(product); db.SaveChanges(); return(RedirectToAction("index")); }
public ActionResult AddtoCart(int?id) { Tproduct product = db.Tproduct.Where(x => x.product_id == id).SingleOrDefault(); var idList = Session["products"] as List <Tproduct>; idList.Add(product); Session["products"] = idList; return(RedirectToAction("index")); }
public void CreateNewProduct(Tproduct efProduct) { try { using (var context = new GiftCardDBContext()) { context.Tproduct.Add(efProduct); context.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public ActionResult ProductDetails(int?id) { ProductDetails productDetails = new ProductDetails(); Tproduct product = db.Tproduct.Where(x => x.product_id == id).SingleOrDefault(); productDetails.product_id = product.product_id; productDetails.product_name = product.product_name; productDetails.product_image = product.product_image; productDetails.product_price = product.product_price; Tcategory category = db.Tcategory.Where(x => x.category_id == product.product_fk_category).SingleOrDefault(); productDetails.category_name = category.category_name; Tuser user = db.Tuser.Where(x => x.Tuser_id == product.product_fk_user).SingleOrDefault(); productDetails.Tuser_name = user.Tuser_name; productDetails.Tuser_image = user.Tuser_image; productDetails.Tuser_contact = user.Tuser_contact; productDetails.product_fk_user = user.Tuser_id; return(View(productDetails)); }
public Tproduct ConvertToEntity() { var efProduct = new Tproduct(); efProduct.Name = this.Name; efProduct.Code = string.Format("P{0}", DateTime.Now.Second + new Random().Next()); //ååįžå· efProduct.SupplierName = BelongSupplier; efProduct.DeliveryAddress = this.DeliveryArea; efProduct.Class1 = this.Class1; efProduct.Class2 = this.Class2; efProduct.SalePrice = this.Price; efProduct.TotalStock = this.AvaliableStock; efProduct.SaledStock = this.SaleAmount; efProduct.Cost = this.Cost; efProduct.Description = this.ProductDetail; efProduct.Status = "0"; efProduct.CreateTime = DateTime.Now; efProduct.UpdateTime = DateTime.Now; return(efProduct); }