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 Create(TimeLineModel model) { ApiResult <bool> result = new ApiResult <bool>(); //编写创建model逻辑 using (var dbContext = new TimeLineDb()) { TimeLineModel newModel = model; try { newModel.CreateTime = DateTime.Now; newModel.UpdateTime = DateTime.Now; newModel.IsDeleted = false; dbContext.timeLineModels.Add(newModel); int ret = dbContext.SaveChanges(); if (ret > 0) { result.Code = 10000; result.Data = true; result.IsSuccess = true; } else { result.Code = 20000; result.Data = false; result.IsSuccess = false; } } catch (Exception e) { Console.Write(e.Message); } } return(Json(result, JsonRequestBehavior.AllowGet)); }
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)); }