public ActionResult NewTravelRequest(NewTravelRequestModel model) { ViewBag.UserEmp_ID=TravelBizLayer.TravelUserEmp_IDBiz(User.Identity.Name); ViewBag.NextReq_ID=TravelBizLayer.TravelNextReq_IDBiz(); ViewBag.AgentList = TravelBizLayer.AgentListBiz(); if (ModelState.IsValid) { try { if (!TravelBizLayer.TravelReqBiz(model)) return View("Error"); ViewBag.Message = "Travel Request Registered! <a href=\"/Employee\">Go to Home page</a>"; return View("Success"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
public static bool TravelReqDAL(NewTravelRequestModel userData) { SqlDatabase travelMSysDB = new SqlDatabase(ConnString.DBConnectionString); SqlCommand insertCmmnd = new SqlCommand("INSERT INTO TRAVEL_REQUESTS ([Emp_ID],[Trip_Name],[Travel_Type_Purpose],[Travel_Date],[Mode_of_Travel],[Travel_Class],[Source_City],[Destination_City],[Travel_Time_hh],[Travel_Time_mm],[First_Level_Approver],[Agent_ID],[Remarks]) VALUES (@Emp_ID,@Trip_Name,@Travel_Type_Purpose,@Travel_Date,@Mode_of_Travel,@Travel_Class,@Source_City,@Destination_City,@Travel_Time_hh,@Travel_Time_mm,@First_Level_Approver,@Agent_ID,@Remarks)"); insertCmmnd.CommandType = CommandType.Text; insertCmmnd.Parameters.AddWithValue("@Emp_ID", userData.Emp_ID); insertCmmnd.Parameters.AddWithValue("@Trip_Name", userData.Trip_Name); insertCmmnd.Parameters.AddWithValue("@Travel_Type_Purpose", userData.Travel_Type_Purpose); insertCmmnd.Parameters.AddWithValue("@Travel_Date", userData.Travel_Date); insertCmmnd.Parameters.AddWithValue("@Mode_of_Travel", userData.Mode_of_Travel); insertCmmnd.Parameters.AddWithValue("@Travel_Class", userData.Travel_Class); insertCmmnd.Parameters.AddWithValue("@Source_City", userData.Source_City); insertCmmnd.Parameters.AddWithValue("@Destination_City", userData.Destination_City); insertCmmnd.Parameters.AddWithValue("@Travel_Time_hh", userData.Travel_Time_hh); insertCmmnd.Parameters.AddWithValue("@Travel_Time_mm", userData.Travel_Time_mm); insertCmmnd.Parameters.AddWithValue("@First_Level_Approver", userData.First_Level_Approver); insertCmmnd.Parameters.AddWithValue("@Agent_ID", userData.Agent_ID); insertCmmnd.Parameters.AddWithValue("@Remarks", userData.Remarks); int rowsAffected = travelMSysDB.ExecuteNonQuery(insertCmmnd); Console.Write("rowsAffected " + rowsAffected); if (rowsAffected == 1) return true; return false; }