public ActionResult Create(FormCollection collection) { if (Session["LogedUserID"] != null) { var languagename = ""; var languageid = ""; ViewBag.successMessage = ""; ViewBag.errorMessage = ""; try { var action = Request.Form["action"].ToString(); if (action == "create") { languagename = Request.Form["languagename"].ToString(); var language = ( from p in db.Languages where (p.languageName == languagename && p.active == true) select p ).FirstOrDefault(); if (language != null) { ViewBag.successMessage = ""; ViewBag.errorMessage = "Language already exists"; } if (language == null) { db.SP_AddLanguage(languagename, Session["LogedUserID"].ToString()); db.SaveChanges(); ViewBag.successMessage = "Record has been saved successfully"; ViewBag.errorMessage = ""; } } if (action == "edit") { languageid = Request.Form["id"].ToString(); languagename = Request.Form["languagename"].ToString(); //var language = ( // from p in db.Languages // where (p.languageName == languagename && p.active == true) // select p // ).FirstOrDefault(); //if (language != null) //{ // ViewBag.successMessage = ""; // ViewBag.errorMessage = "Language already exists"; //} //if (language == null) //{ db.sp_UpdateLanguages(Convert.ToInt64(languageid), languagename, Session["LogedUserID"].ToString(), System.DateTime.Now); db.SaveChanges(); ViewBag.successMessage = "Record has been saved successfully"; ViewBag.errorMessage = ""; //} } if (action == "delete") { languageid = Request.Form["id"].ToString(); db.sp_DeleteLanguage(Convert.ToInt64(languageid), Session["LogedUserID"].ToString(), System.DateTime.Now); db.SaveChanges(); ViewBag.successMessage = "Record has been deleted successfully"; ViewBag.errorMessage = ""; } var __existinglangList = db.SP_SelectLanguages(); return(View(__existinglangList)); } catch (Exception ex) { ViewBag.errorMessage = "Error occurred while processing your request."; var _existinglangList = db.SP_SelectLanguages(); return(View(_existinglangList)); } } else { return(RedirectToAction("AdminLogin", "Account")); } }