public bool SaveChangesToDB(Controller c, weightlogEntities db, object[] records, bool isEdit = false) { try { foreach (object record in records) { Type recordType = record.GetType(); if (isEdit) { db.Entry(record).State = EntityState.Modified; } DbSet dbSet = db.Set(record.GetType()); if (!isEdit) { dbSet.Add(record); } } db.SaveChanges(); c.TempData["RecordSaved"] = "Success"; return(true); } catch (Exception e) { c.TempData["RecordSaved"] = "Failed"; return(false); } }
// GET: WeightList/Delete/2018-06-19 public ActionResult Delete(string id) { var weight_list_original = GetWeightRecord(id, db); db.weight_list.Remove(weight_list_original); db.SaveChanges(); return(RedirectToAction("Index")); }