public ActionResult Update(TimeLineModel model) { ApiResult <TimeLineModel> result = new ApiResult <TimeLineModel>(); using (var db = new TimeLineDb()) { var dbmodel = db.timeLineModels.Where(p => p.Id == model.Id).First(); if (dbmodel != null) { dbmodel.Copy = model.Copy; dbmodel.Images = model.Images; dbmodel.TitleYear = model.TitleYear; dbmodel.TitleMonth = model.TitleMonth; dbmodel.TitleDay = model.TitleDay; dbmodel.UpdateTime = DateTime.Now; } db.Entry(dbmodel).State = System.Data.Entity.EntityState.Modified; var ret = db.SaveChanges(); if (ret > 0) { result.Code = 200; result.Data = dbmodel; result.IsSuccess = true; } return(Json(result)); } }
public ActionResult Delete(int id) { ApiResult <bool> result = new ApiResult <bool>(); int ret = 0; using (var db = new TimeLineDb()) { var model = db.timeLineModels.Where(p => p.Id == id).First(); if (model != null) { model.IsDeleted = true; model.UpdateTime = DateTime.Now; db.Entry(model).State = System.Data.Entity.EntityState.Modified; ret = db.SaveChanges(); } } if (ret > 0) { result.Code = 200; result.Data = true; result.IsSuccess = true; } else { result.Code = 500; result.Data = false; result.IsSuccess = false; } return(Json(result)); }