public JsonResult CreateMomoAPI([Bind(Include = "ID,NanpreNO,MakeUserID,IsPublic,Title,Remarks")] Momo momo) { if (ModelState.IsValid) { //SaveChangesを二回行うので本当は両方を範囲としたトランザクションが必要 momo.CreatedDateTime = DateTime.Now; momo.IsCleared = false; momo.NanpreNO = Int16.Parse(Request.QueryString["NanpreNO"].ToString()); momo.Title = Request.QueryString["Title"].ToString(); momo.MakeUserID = Request.QueryString["MakeUserID"].ToString(); momo.IsPublic = Request.QueryString["IsPublic"].ToString() == "True" ? true : false; momo.Remarks = string.Empty; db.Momoes.Add(momo); db.SaveChanges(); var momoState = new MomoState() { Momo_ID = momo.ID, CurrentNanpre = db.NanpreQuestions.FirstOrDefault(x => x.ID == momo.NanpreNO).Nanpre }; //CurrentNanpreがnullの場合の対応はいつかやる db.MomoStates.Add(momoState); db.SaveChanges(); return(null); } return(null); }
public ActionResult Create([Bind(Include = "ID,NanpreNO,MakeUserID,IsPublic,Title,Remarks")] Momo momo) { if (ModelState.IsValid) { //SaveChangesを二回行うので本当は両方を範囲としたトランザクションが必要 momo.CreatedDateTime = DateTime.Now; momo.IsCleared = false; db.Momoes.Add(momo); db.SaveChanges(); var momoState = new MomoState() { Momo_ID = momo.ID, CurrentNanpre = db.NanpreQuestions.FirstOrDefault(x => x.ID == momo.NanpreNO).Nanpre }; //CurrentNanpreがnullの場合の対応はいつかやる db.MomoStates.Add(momoState); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(momo)); }