public OperationResult SaveRoute(Route route) { OperationResult result = new OperationResult(); var routeDetails = new DataTable(); routeDetails.Columns.Add("RouteID", typeof(int)); routeDetails.Columns.Add("Username", typeof(string)); routeDetails.Columns.Add("Title", typeof(string)); routeDetails.Columns.Add("Description", typeof(string)); routeDetails.Columns.Add("Speed", typeof(float)); routeDetails.Columns.Add("StartTime", typeof(string)); routeDetails.Columns.Add("EndTime", typeof(string)); routeDetails.Columns.Add("Distance", typeof(float)); routeDetails.Columns.Add("WeatherInfo", typeof(string)); var routePoints = new DataTable(); routePoints.Columns.Add("latitude", typeof(Double)); routePoints.Columns.Add("longitude", typeof(Double)); routeDetails.Rows.Add(new Object[] {route.routeid,route.username,route.title,route.description,route.speed,route.starttime,route.endtime,route.distance,route.weatherinfo}); foreach (RoutePoint point in route.pointCollection) { routePoints.Rows.Add(new Object[] {point.latitude,point.longitude}); } try { using (con = new SqlConnection(connectionString)) { con.Open(); using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_insertRoute"; var routeParam = cmd.Parameters.AddWithValue("@route", routeDetails); var routePointsParams = cmd.Parameters.AddWithValue("@routePoints", routePoints); routeParam.SqlDbType = SqlDbType.Structured; routePointsParams.SqlDbType = SqlDbType.Structured; SqlParameter result_param = new SqlParameter("@result", SqlDbType.Int); result_param.Direction = ParameterDirection.Output; cmd.Parameters.Add(result_param); cmd.ExecuteNonQuery(); int status = Convert.ToInt32(result_param.Value); if (status == 1) { result.status = true; result.Message = "Saved Route Successfully"; } else if (status == 0) { result.status = false; result.Message = "Exception in Procedure"; } else if (status == 2) { result.status = false; result.Message = "Duplicate"; } else if (status == 3) { result.status = false; result.Message = "Invalid User"; } } } } catch (Exception ex) { result.status = false; result.Message = ex.Message; sEvent = ex.Message; if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog); EventLog.WriteEntry(sSource, sEvent); EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Error, 234); } return result; }
public OperationResult Login(string userid, string password) { OperationResult result = new OperationResult(); try { using (con = new SqlConnection(connectionString)) { con.Open(); using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_get_password"; var userid_param = cmd.Parameters.AddWithValue("@username", userid); SqlParameter password_param = new SqlParameter("@password", SqlDbType.VarChar); password_param.Direction = ParameterDirection.Output; password_param.Size = 8000; cmd.Parameters.Add(password_param); userid_param.SqlDbType = SqlDbType.NVarChar; cmd.ExecuteNonQuery(); if (password == password_param.Value as string) { result.status = true; result.Message = "User Logged In"; } else { result.status = false; result.Message = "User Login Failed"; } } } } catch (Exception ex) { result.status = false; result.Message = "Data Exception"; } return result; }
public List<OperationResult> SaveRoute(Stream body) { List<OperationResult> result = new List<OperationResult>(); try { BikingDAL dal = new BikingDAL(); string jsonData = getPostData(body); if (!string.IsNullOrEmpty(jsonData)) { RoutesCollection routes = getRoute(jsonData); if (routes != null) { foreach (Route currentRoute in routes.routeCollection) { OperationResult curr_result = dal.SaveRoute(currentRoute); curr_result.routeid = currentRoute.routeid; result.Add(curr_result); } } else { OperationResult error_result = new OperationResult(); error_result.status = false; error_result.Message = "JSON Parse Exception"; result.Add(error_result); } } else { OperationResult error_result = new OperationResult(); error_result.status = false; error_result.Message = "Post Params Empty"; result.Add(error_result); } } catch (Exception ex) { OperationResult error_result = new OperationResult(); error_result.status = false; error_result.Message = ex.Message; result.Add(error_result); } return result; }
public User signup(Stream data) { OperationResult result = new OperationResult(); User currentUser = null; try { string s_params = getPostData(data); NameValueCollection postParams = HttpUtility.ParseQueryString(s_params); string userid = postParams["uname"]; string password = postParams["passwd"]; BikingDAL dal = new BikingDAL(); int returnVal = dal.InsertUser(userid, password); if (1==returnVal) { currentUser = new User(); currentUser.user = userid; currentUser.pass = password; } else if (2 == returnVal) { currentUser = new User(); currentUser.user = userid; currentUser.pass = password; currentUser.ERROR = "Duplicate"; } } catch (Exception ex) { //result.status = false; //result.Message = ex.Message; } return currentUser; }
public User login(Stream data) { OperationResult result = new OperationResult(); User currentUser = null; try { string s_params = getPostData(data); NameValueCollection postParams = HttpUtility.ParseQueryString(s_params); string userid = postParams["username"]; string password = postParams["password"]; BikingDAL dal = new BikingDAL(); result = dal.Login(userid, password); if (result.status) { currentUser = new User(); currentUser.user = userid; currentUser.pass = password; return currentUser; } } catch (Exception ex) { //result.status = false; //result.Message = ex.Message; } return currentUser; }