public IActionResult ActionEdit(yuActivityViewModel p) { if (p != null) { if (p.img != null) { string pohotoname = Guid.NewGuid().ToString() + ".jpg"; using (var photo = new FileStream(iv_host.WebRootPath + @"\imgs\" + pohotoname, FileMode.Create)) { p.img.CopyTo(photo); } p.CPicture = @"../imgs/" + pohotoname; } 擺腹BuyFoodContext db = new 擺腹BuyFoodContext(); TActivity table = db.TActivities.FirstOrDefault(a => a.CActivityId == p.CActivityId); if (table != null) { table.CActivityName = p.CActivityName; table.CDescription = p.CDescription; table.CLink = p.CLink; table.CStatus = p.CStatus; if (p.CPicture != null) { table.CPicture = p.CPicture; } db.SaveChanges(); } } return(RedirectToAction("ActivityList")); }
public IActionResult ActivityCreat(yuActivityViewModel p) { string pohotoname = Guid.NewGuid().ToString() + ".jpg"; using (var photo = new FileStream(iv_host.WebRootPath + @"\imgs\" + pohotoname, FileMode.Create)) { p.img.CopyTo(photo); } p.CPicture = @"../imgs/" + pohotoname; p.CTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); 擺腹BuyFoodContext db = new 擺腹BuyFoodContext(); db.TActivities.Add(p.Activity); db.SaveChanges(); return(RedirectToAction("ActivityList")); }