//POST: Insert to database logic public ActionResult Insert(mg_shoplist2 costDt) { var userobject = Session["id"]; if (userobject == null) { return(RedirectToAction("Index", "Login")); } else { //var dates = Convert.ToDateTime(costDt.TRANS_DATE_STR).ToString("MM/dd/yyyy"); costDt.TRANS_DATE = Convert.ToDateTime(costDt.TRANS_DATE_STR); var editmode = Request.QueryString["editmode"]; var username = User.Identity.Name; var dtname = username; mg_shoplist form = new mg_shoplist(); form.AMOUNT = costDt.AMOUNT; form.TRANS_DATE = costDt.TRANS_DATE; form.NOTES = costDt.NOTES; form.ENTRY_DATE = DateTime.Now; form.ENTRY_USER = userobject.ToString(); form.UPDATE_DATE = DateTime.Now; form.UPDATE_USER = userobject.ToString(); using (db) { try { db.mg_shoplist.Add(form); db.SaveChanges(); return(Json(new { success = true, message = "Saved successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { success = false, message = e.InnerException.Message }, JsonRequestBehavior.AllowGet)); } } } }
//POST: Update to database logic public ActionResult Update(mg_shoplist2 costDt) { var userobject = Session["id"]; if (userobject == null) { return(RedirectToAction("Index", "Login")); } else { var editmode = Request.QueryString["editmode"]; var username = User.Identity.Name; var datestr = costDt.TRANS_DATE_STR; costDt.TRANS_DATE = Convert.ToDateTime(datestr); costDt.UPDATE_DATE = DateTime.Now; costDt.UPDATE_USER = userobject.ToString(); using (db) { var id = costDt.ID; var dtfromdb = db.mg_shoplist.Find(id); dtfromdb.NOTES = costDt.NOTES; dtfromdb.AMOUNT = costDt.AMOUNT; dtfromdb.TRANS_DATE = costDt.TRANS_DATE; dtfromdb.UPDATE_DATE = costDt.UPDATE_DATE; dtfromdb.UPDATE_USER = costDt.UPDATE_USER; try { db.Entry(dtfromdb).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { success = false, message = e.InnerException.Message }, JsonRequestBehavior.AllowGet)); } } } }
public ActionResult Edit(string costid) { var userobject = Session["id"]; if (userobject == null) { return(RedirectToAction("Index", "Login")); } else { costid = Request.QueryString["costid"]; int ids = Convert.ToInt32(costid); using (db) { var formDt = db.mg_shoplist.Where(x => x.ID == ids).FirstOrDefault <mg_shoplist>(); mg_shoplist2 forms = new mg_shoplist2(); forms.ID = formDt.ID; forms.TRANS_DATE_STR = formDt.TRANS_DATE.ToString("dd/MM/yyyy"); forms.AMOUNT = formDt.AMOUNT; forms.NOTES = formDt.NOTES; return(View(forms)); } } }