示例#1
0
 public ActionResult Edit(TableCreateViewModel model)
 {
     model.Validate(ModelState);
     if (ModelState.IsValid)
     {
         var table = _db.Tables.Find(model.Id);
         table.Name             = model.Name;
         table.Location         = model.Location;
         table.SideOneColor     = model.SideOneColor;
         table.SideTwoColor     = model.SideTwoColor;
         _db.Entry(table).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     model.Colors = new SelectList(Enum.GetValues(typeof(Table.Color)));
     return(View(model));
 }
示例#2
0
 public ActionResult Create(TableCreateViewModel model)
 {
     model.Validate(ModelState);
     if (ModelState.IsValid)
     {
         var table = new Table
         {
             Name         = model.Name,
             Location     = model.Location,
             SideOneColor = model.SideOneColor,
             SideTwoColor = model.SideTwoColor
         };
         _db.Tables.Add(table);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     model.Colors = new SelectList(Enum.GetValues(typeof(Table.Color)));
     return(View(model));
 }