// GET: YGoods/Create public ActionResult Create() { ViewBag.Type = new SelectList(db.YGoodsType, "ID", "Name"); var model = new YGoodsView(); return(View(model)); }
// GET: YGoods/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } YGoods model = db.YGoods.Find(id); var models = new YGoodsView { ID = model.ID, Info = model.Info, Type = model.Type, GoodsName = model.GoodsName, //MainImage = model.MainImage, Price = model.Price, //SamllImage = model.SamllImage, Stock = model.Stock, Mark = model.Mark }; models.MainImage.Images = model.MainImage?.Split(',') ?? new string[0]; models.SamllImage.Images = model.SamllImage?.Split(',') ?? new string[0]; ViewBag.Type = new SelectList(db.YGoodsType.OrderBy(s => s.ID), "ID", "Name", models.Type); if (model == null) { return(HttpNotFound()); } return(View(models)); }
public ActionResult Edit(YGoodsView goods) { if (ModelState.IsValid) { var t = db.YGoods.FirstOrDefault(s => s.ID == goods.ID); t.ID = goods.ID; t.GoodsName = goods.GoodsName; t.MainImage = string.Join(",", goods.MainImage.Images); t.Price = goods.Price; t.SamllImage = string.Join(",", goods.SamllImage.Images); t.Stock = goods.Stock; t.Type = goods.Type; t.Info = goods.Info; t.Mark = goods.Mark; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(goods)); }
public ActionResult Create(YGoodsView yGoods) { if (ModelState.IsValid) { var model = new YGoods { GoodsName = yGoods.GoodsName, Type = yGoods.Type, Stock = yGoods.Stock, SamllImage = string.Join(",", yGoods.SamllImage.Images), Info = yGoods.Info, MainImage = string.Join(",", yGoods.MainImage.Images), Price = yGoods.Price, Mark = yGoods.Mark }; db.YGoods.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(yGoods)); }