public DataTable GetTableData(Models.Database database, string tablename) { DataTable dataTable = new DataTable(); string conString = string.Empty; if (database.authentication == "WA") { conString = "Data Source=" + database.servername + ";Initial Catalog =" + database.database + ";Integrated Security=True"; } else if (database.authentication == "SQL") { conString = "Data Source=" + database.servername + ";Initial Catalog =" + database.database + ";Integrated Security=False; User ID = " + database.username + "; Password = "******""; } using (SqlConnection con = new SqlConnection(conString)) { con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM " + tablename + "", con); var dataReader = cmd.ExecuteReader(); DataTable dtSchema = dataReader.GetSchemaTable(); dataTable.Load(dataReader); con.Close(); } return(dataTable); }
public static SystemConf GetSystemConf() { using (Models.Database db = new Models.Database()) { return(db.SystemConf.FirstOrDefault()); } }
public static void LogException(Exception e, Models.Fault Fault) { try { string eInnerString = "No InnerException"; if (e.InnerException != null) { eInnerString = e.InnerException.ToString(); } using (var db = new Models.Database()) { var exception = new Models.ExceptionLog(); exception.Data = e.Data.ToString(); exception.Fault = Fault.ToString(); exception.Message = e.Message; exception.Time = DateTime.UtcNow; exception.Exception = eInnerString; exception.StackTrace = e.StackTrace; exception.Method = e.TargetSite.Name; exception.Source = e.Source; db.ExceptionLogs.Add(exception); db.SaveChanges(); System.Diagnostics.Debug.WriteLine("Exception was logged to the database successfully."); } } catch { System.Diagnostics.Debug.WriteLine("Failed to log exception to database. We probably broke that too. :("); } }
public Models.BU.Module GetSingleModule(int moduleId) { Models.Database db = new Models.Database(); string query = "SELECT * FROM Module WHERE ModuleId = '" + moduleId + "'"; return(db.GetSingleModule(query)); }
public Models.BU.Module GetModuleByModuleCode(string moduleCode) { Models.Database db = new Models.Database(); string query = "SELECT * FROM Module WHERE Code = '" + moduleCode + "'"; return(db.GetSingleModule(query)); }
public List <Models.BU.Wish> GetTeacherWishes(int userId) { Models.Database db = new Models.Database(); string query = "SELECT * FROM Wish WHERE UserId = '" + userId + "'"; return(db.GetTeacherWishes(query)); }
public List <Models.BU.Module> GetModuleListOfTeacher(int userId) { Models.Database db = new Models.Database(); string query = "SELECT DISTINCT m.* FROM Module m, ModuleUser mu, UserAccount ua WHERE ua.UserId = mu.UserId AND mu.ModuleId = m.ModuleId AND ua.UserId = '" + userId + "'"; return(db.GetModuleListOfTeacher(query)); }
public Models.BU.Teacher GetSingleTeacher(int userId) { Models.Database db = new Models.Database(); string query = "SELECT * FROM UserAccount WHERE Role = '2' AND UserId = '" + userId + "' OR Role = '3' AND UserId = '" + userId + "'"; return(db.GetSingleTeacher(query)); }
public List <Models.BU.Lecture> GetLecturesOfTeacher(int userId) { Models.Database db = new Models.Database(); string query = "SELECT * FROM Lecture WHERE TeacherId = '" + userId + "'"; return(db.GetLecturesOfTeacher(query, userId)); }
public int UsernameToUserId(string username) { Models.Database db = new Models.Database(); string query = "SELECT UserId FROM UserAccount WHERE Username = '******'"; return(db.UsernameToUserId(query)); }
public string UserIdToUsername(int userId) { Models.Database db = new Models.Database(); string query = "SELECT Username FROM UserAccount WHERE UserId = '" + userId + "'"; return(db.UserIdToUsername(query)); }
public void DeleteEntry(int lectureId) { Models.Database db = new Models.Database(); string query = "DELETE FROM Lecture WHERE lectureId = '" + lectureId + "'"; db.DeleteEntry(query); }
public List <int> GetAvailableDays(int userId, int period, int week) { Models.Database db = new Models.Database(); string query = "SELECT DISTINCT Day FROM Wish WHERE UserId = '" + userId + "' AND Period = '" + period + "' AND Week = '" + week + "'"; return(db.GetAvailableDays(query)); }
public ActionResult MobilePhoneService(HttpPostedFileBase Image, HttpPostedFileBase Image1, HttpPostedFileBase Image2, HttpPostedFileBase Image3, HttpPostedFileBase Image4, String condition, String Heading, String description, String price, String negotiable) { TheValues tv = new TheValues(); String x = (Convert.ToInt32(space(tv.getTheLastPID())) + 1).ToString(); Images(Image, Image1, Image2, Image3, Image4, x); Models.MobilePhone mb = new Models.MobilePhone(); mb.FixedDetails = "কন্ডিশন: " + condition + " <br/> "; mb.UserDetails = "বিজ্ঞাপন শিরোনাম: " + Heading + " <br/> " + "বিবরণ: " + description + ""; mb.Price = price + "" + negotiable; Models.Database db = new Models.Database(); db.DatabaseCon("EAlo"); db.setData("Insert into ApproveTable(DTB,Cat,City,Region,FixedDetails,Price,UID,UserDetails,PID,img1,img2,img3,img4,img5,Phone) values(" + "'" + Session["DTB"].ToString() + "'," + "'" + Session["Cat"].ToString() + "'," + "'" + Session["City"].ToString() + "'," + "'" + Session["Region"].ToString() + "'," + "'" + AscciStar(mb.FixedDetails) + "'," + "'" + AscciStar(mb.Price) + "'," + "'" + Session["Email"].ToString() + "'," + "'" + AscciStar(mb.UserDetails) + "'," + "'" + x + "'," + "'" + this.img1 + "'," + "'" + this.img2 + "'," + "'" + this.img3 + "'," + "'" + this.img4 + "'," + "'" + this.img5 + "'," + "'" + Session["Phone"].ToString() + "'" + ")"); db.DatabaseCon("EAlo"); db.setData("Update ApproveTable set PID= '" + x + "' where UID='UID'"); return(Redirect("~/Confirm/Confirm")); // return Redirect("~/Mobile/MobilePhoneService?Area=" + Session["City"] + "***" + Session["Region"] + "***" + Session["DTB"] + "***" + Session["Cat"]); }
public void InsertIntoTempTable(Models.Database database, DataTable tempTableDT) { string conString = string.Empty; if (database.authentication == "WA") { conString = "Data Source=" + database.servername + ";Initial Catalog =" + "tempdb" + ";Integrated Security=True"; } else if (database.authentication == "SQL") { conString = "Data Source=" + database.servername + ";Initial Catalog =" + "tempdb" + ";Integrated Security=False; User ID = " + database.username + "; Password = "******""; } using (var bulkCopy = new SqlBulkCopy(conString)) { // my DataTable column names match my SQL Column names, so I simply made this loop. However if your column names don't match, just pass in which datatable name matches the SQL column name in Column Mappings foreach (DataColumn col in tempTableDT.Columns) { bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName); } bulkCopy.BulkCopyTimeout = 600; bulkCopy.DestinationTableName = tempTableDT.TableName; bulkCopy.WriteToServer(tempTableDT); } }
public static TwitterContext GetContext(int iRobotID, out string UserID) { using (var db = new Models.Database()) { return(new TwitterContext(GetAuthorization(db.TwitterAccounts.First(l => l.ID == iRobotID), out UserID))); } }
public static void BuildLocationJS(int HitchBotID) { using (var db = new Models.Database()) { var locations = db.hitchBOTs.Include(l => l.Locations).SingleOrDefault(l => l.ID == HitchBotID).Locations.Where(l => l.TakenTime > new DateTime(2014, 07, 27, 13, 30, 0)).OrderBy(l => l.TakenTime).ToList(); var slimmedLocations = LocationHelper.SlimLocations(locations); string builder = "var flightPlanCoordinates = [ "; foreach (Models.Location myLocation in slimmedLocations) { builder += "\n new google.maps.LatLng(" + myLocation.Latitude + "," + myLocation.Longitude + "),"; } builder += @" ]; var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, geodesic: true, strokeColor: '#E57373', //taken from material design by google strokeOpacity: 1.0, strokeWeight: 2 }); function AddPolyFill(map){ flightPath.setMap(map); }"; System.IO.File.WriteAllText(Helpers.PathHelper.GetJsBuildPath() + Helpers.AzureBlobHelper.JS_LOCATION_FILE_NAME + Helpers.AzureBlobHelper.JS_FILE_EXTENSION, builder); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["New"] != null) { var user = (Models.Password)Session["New"]; using (var db = new Models.Database()) { this.hitchbotID = user.hitchBOT.ID; //if there is a project available, display the info for that one instead. if (user.Projects.FirstOrDefault() != null) this.projectID = user.Projects.First().ID; var lastLocationTime = db.Locations.Where(l => l.HitchBOT.ID == this.hitchbotID) .OrderByDescending(l => l.TakenTime) .First().TakenTime; if (!IsPostBack) { LocationLBL.Text += lastLocationTime.ToString() + " (UTC)"; MapTimeLBL.Text += Map_Generation_Time.ToString() + " (UTC)"; } } } else { Response.Redirect("Unauthorized.aspx"); } }
public ActionResult Edit(int id, [Bind(Include = "PostID,Title,ShortDescription,Description,Published,PostedOn,Modified,Category_id")] Post newPost) { List <string> tagList = new List <string>(); if (Request.HttpMethod == "POST") { // Post request method var tags = Request.Form["tags"].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // Save content PostManager.Update(id, newPost, tags.ToList()); // Redirect Response.Redirect("~/home"); } else { // Find the required post. Post NewPost = new Post(); using (Models.Database bd = new Models.Database()) { NewPost = bd.Post.Where(b => b.PostID == id).First(); var tg = from s in db.Tag join sa in db.PostTagMap on s.TagID equals sa.Post_Tag where sa.Post_ID == id select s.Name; tagList = tg.ToList(); } ViewBag.Found = true; ViewBag.Tags = tagList; ViewBag.Category_id = new SelectList(db.Category, "CategoryID", "Name", NewPost.Category_id); return(View(NewPost)); } return(RedirectToAction("Index")); }
public override bool PerformAction() { this.SendConfirmPacket(); using (var db = new Models.Database()) { var robotTweets = db.Robots.First(l => l.ID == this.ROBOT_ID).TwitterAccount.Tweets; this.SendSingeBytePacket((byte)Math.Min(robotTweets.Count, MAX_SEND_TWEETS)); var robotTweetsText = robotTweets.Skip(Math.Max(0, robotTweets.Count() - MAX_SEND_TWEETS)).Take(MAX_SEND_TWEETS).Select(l => l.TweetText).ToList(); // Helpers.Markov.removeSpecialCharacters(robotTweetsText); StringBuilder sb = new StringBuilder(); foreach (var tweet in robotTweetsText) { sb.AppendLine(tweet); } var tempString = sb.ToString(); var tempBytes = Encoding.ASCII.GetBytes(tempString); this.SendAllBytes(tempBytes); this.SendConfirmPacket(); this.CloseConnection(); } return(true); }
public ActionResult SaveUser(string name, string username, string password) { Models.Database db = new Models.Database(); return(Content(db.AddUser(new Models.User { Name = name, MsgCount = 0, Username = username, Password = password, LastLogin = DateTime.Today.Date.ToString("yyyy-MM-dd"), Attempts = 0 }).Status)); }
public ActionResult Approve() { String UID = Request.Params["UID"].ToString(); String PID = Request.Params["PID"].ToString(); Models.Database db = new Models.Database(); ApproveData apd = new ApproveData(); String[] x = apd.getData(UID, PID); db.DatabaseCon("EAloAllInfo"); db.setData("Insert into InfoTable (Dates,DTB,Cat,City,Region,FixedDetails,UserDetails,Price,UID,PID,Phone,img1,img2,img3,img4,img5) values(" + "'" + "Dates" + "'," + "'" + x[0] + "'," + "'" + x[1] + "'," + "'" + x[2] + "'," + "'" + x[3] + "'," + "'" + x[4] + "'," + "'" + x[5] + "'," + "'" + x[6] + "'," + "'" + x[7] + "'," + "'" + x[8] + "'," + "'" + x[9] + "'," + "'" + x[10] + "'," + "'" + x[11] + "'," + "'" + x[12] + "'," + "'" + x[13] + "'," + "'" + x[14] + "'" + ")"); //db.DatabaseCon("EAloAllInfo").Close(); db.DatabaseCon("EAloCity"); db.setData("Insert into " + Space(x[2]) + " (Dates,DTB,Cat,City,Region,FixedDetails,UserDetails,Price,UID,PID,Phone,img1,img2,img3,img4,img5) values(" + "'" + "Dates" + "'," + "'" + x[0] + "'," + "'" + x[1] + "'," + "'" + x[2] + "'," + "'" + x[3] + "'," + "'" + x[4] + "'," + "'" + x[5] + "'," + "'" + x[6] + "'," + "'" + x[7] + "'," + "'" + x[8] + "'," + "'" + x[9] + "'," + "'" + x[10] + "'," + "'" + x[11] + "'," + "'" + x[12] + "'," + "'" + x[13] + "'," + "'" + x[14] + "'" + ")"); /// db.DatabaseCon("EAloCity").Close(); db.DatabaseCon("EAlo" + Space(x[0])); db.setData("Insert into " + "Cetagory" + " (Dates,DTB,Cat,City,Region,FixedDetails,UserDetails,Price,UID,PID,Phone,img1,img2,img3,img4,img5) values(" + "'" + "Dates" + "'," + "'" + x[0] + "'," + "'" + x[1] + "'," + "'" + x[2] + "'," + "'" + x[3] + "'," + "'" + x[4] + "'," + "'" + x[5] + "'," + "'" + x[6] + "'," + "'" + x[7] + "'," + "'" + x[8] + "'," + "'" + x[9] + "'," + "'" + x[10] + "'," + "'" + x[11] + "'," + "'" + x[12] + "'," + "'" + x[13] + "'," + "'" + x[14] + "'" + ")"); // db.DatabaseCon("EAlo" + Space(x[0])).Close(); db.DatabaseCon("EAlo"); db.setData("Delete from ApproveTable where UID=" + "'" + UID + "' and PID=" + "'" + PID + "'"); // db.DatabaseCon("EAlo").Close(); return(Redirect("~/Admin/Admin?Password=EAlo&Admin=EAlo")); }
public List <string> GetTablesList(Models.Database database) { var tables = new List <string>(); string conString = string.Empty; if (database.authentication == "WA") { conString = "Data Source=" + database.servername + ";Initial Catalog =" + database.database + ";Integrated Security=True"; } else if (database.authentication == "SQL") { conString = "Data Source=" + database.servername + ";Initial Catalog =" + database.database + ";Integrated Security=False; User ID = " + database.username + "; Password = "******""; } using (SqlConnection con = new SqlConnection(conString)) { con.Open(); using (SqlCommand cmd = new SqlCommand("select CONCAT(schema_name(schema_id),'.',name) AS table_name from sys.tables order by table_name;", con)) { using (IDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { tables.Add(dr[0].ToString()); } } } } return(tables); }
public static async void CheckForTargetLocation(int HitchBotID, int LocationID) { using (var db = new Models.Database()) { var location = db.Locations.First(l => l.ID == LocationID); var hitchbot = db.hitchBOTs.First(h => h.ID == HitchBotID); var TargetLocations = db.TwitterLocations.Where(l => l.HitchBot.ID == HitchBotID && l.Status == null).Include(l => l.TargetLocation); foreach (hitchbotAPI.Models.TwitterLocationTarget thisTargetLocation in TargetLocations) { var currentLocation = new GeoCoordinate(location.Latitude, location.Longitude); var targetLocation = new GeoCoordinate(thisTargetLocation.TargetLocation.Latitude, thisTargetLocation.TargetLocation.Longitude); if (currentLocation.GetDistanceTo(targetLocation) <= thisTargetLocation.RadiusKM * 1000) { int TweetID = await Helpers.TwitterHelper.PostTweetWithLocation(HitchBotID, LocationID, thisTargetLocation.TweetText); Task<int> WeatherTweet = TwitterHelper.PostTweetWithLocationAndWeather(HitchBotID, LocationID); LinkTargetLocationToTweet(TweetID, thisTargetLocation.ID); await WeatherTweet; break; } } } }
public static List <TokenOrder> getOrdersForUser(Guid key) { using (Models.Database db = new Models.Database()) { List <TokenOrder> ord = db.TokenOrder.Where(u => u.user_id == key).ToList(); return(ord); } }
public void ThrowArgumenNullException_WhenNullArgumentIsPassed() { //arrange var database = new Models.Database(); //act database.AddProduct(null); }
public void ThrowArgumentException_WhenNullParameterIsPassed() { //arrange var database = new Models.Database(); //assert Assert.ThrowsException <ArgumentException>(() => database.GetList(null)); }
public static User getById(Guid key) { using (Models.Database db = new Models.Database()) { var user = db.User.Where(u => u.user_id == key).FirstOrDefault(); return(user); } }
public static bool EmailExists(string email) { using (Models.Database db = new Models.Database()) { var exists = db.User.Where(u => u.email == email).FirstOrDefault(); return(exists != null); } }
public static User getByEmail(String email) { using (Models.Database db = new Models.Database()) { var user = db.User.Where(u => u.email == email).FirstOrDefault(); return(user); } }
public string GetUsername(int userId) { string query = "SELECT Username FROM UserAccount WHERE UserId = " + userId; Models.Database db = new Models.Database(); db.Connect(); return(db.UserIdToUsername(query)); }
public void ThrowArgumentException_WhenInvalidParameterIsPassed() { //arrange var database = new Models.Database(); string typeString = "Tomatoes"; //assert Assert.ThrowsException <ArgumentException>(() => database.GetList(typeString)); }
public static bool addPanel(Models.LedPanel panel) { using (var db = new Models.Database()) { db.LedPanels.Add(panel); db.SaveChanges(); } return true; }
// GET: Home public ActionResult Index() { using (var db = new Models.Database()) { List <Models.Movie> allMovies = db.Movie.ToList(); return(View(allMovies)); } //return View(); }
private static void LinkTargetLocationToTweet(int TweetID, int TargetLocationID) { using (var db = new Models.Database()) { var status = db.TwitterStatuses.First(ts => ts.ID == TweetID); var Target = db.TwitterLocations.First(tl => tl.ID == TargetLocationID); Target.Status = status; db.SaveChanges(); } }
public static bool addFace(Models.Face face) { using (var db = new Models.Database()) { foreach (var panel in face.Panels) { addPanel(panel); db.LedPanels.Attach(panel); } db.Passwords.Attach(face.UserAccount); db.Faces.Add(face); db.SaveChanges(); } return true; }
public static List<Models.Face> getAllFaces() { List<Models.Face> face = new List<Models.Face>(); using (var db = new Models.Database()) { var query = from f in db.Faces.Include("UserAccount").Include("Panels.Rows") where f.Approved == true orderby f.TimeAdded select f; foreach (var item in query) { face.Add(item); } } return face; }
protected void reload_JS(object sender, EventArgs e) { using (var db = new Models.Database()) { // Get current user, HitchBOT and Project this.user = (Models.Password)Session["New"]; this.HitchBOT = db.hitchBOTs.First(l => l.ID == this.user.hitchBOT.ID); this.Project = db.Projects.Where(p => p.EndTime == null).ToArray().Last(); // Create new builder to build JS files GoogleMapsBuilder = new Helpers.Location.GoogleMapsBuilder(this.HitchBOT.ID, this.Project.ID, this.user.ID); // Build JS using GoogleMapsBuilder GoogleMapsBuilder.BuildJsAndUpload(); } }
public static Models.Face getLastFace(Models.Password user) { List<Models.Face> face = new List<Models.Face>(); using (var db = new Models.Database()) { var query = from f in db.Faces.Include("UserAccount").Include("Panels.Rows") where f.Approved == false && f.UserAccount.ID == user.ID orderby f.TimeAdded select f; foreach (var item in query) { face.Add(item); } } return face[face.Count - 1]; }
public static string GetEncodedPolyLine(int HitchBotID) { using (var db = new Models.Database()) { var OrderedLocations = db.hitchBOTs.Include(h => h.Locations).First(h => h.ID == HitchBotID).Locations.Where(l => l.TakenTime > new DateTime(2014, 07, 27, 13, 30, 0)).OrderBy(l => l.TakenTime).ToList(); string tempRegionString = string.Empty; string tempURL = EncodeCoordsForGMAPS(SlimLocations(OrderedLocations)); if (OrderedLocations.Count > 0) { var mostRecent = OrderedLocations.Last(); try { tempRegionString = GetRegion(mostRecent); } catch { } tempURL += gmapsMarkerString + Math.Round(mostRecent.Latitude, 3) + "," + Math.Round(mostRecent.Longitude, 3); } else { tempRegionString = "Apparently my devs don't know where I am.. They should probably be fixing this and not doing $insert_awesome_activity_here$"; } var hitchBOT = db.hitchBOTs.First(h => h.ID == HitchBotID); var tempStaticLink = new Models.GoogleMapsStatic() { HitchBot = hitchBOT, URL = tempURL, NearestCity = tempRegionString, ViewCount = 1, TimeGenerated = DateTime.UtcNow, TimeAdded = DateTime.UtcNow }; db.StaticMaps.Add(tempStaticLink); db.SaveChanges(); return tempURL; } }
protected void Page_Load(object sender, EventArgs e) { if (Session["New"] != null) { var user = (Models.Password)Session["New"]; using (var db = new Models.Database()) { int hitchBOTid = user.hitchBOT.ID; var status = db.TabletStatusI.Where(ts => ts.HitchBOT.ID == hitchBOTid).OrderByDescending(l => l.TimeTaken).ToList().First(); lblActualLastCheckin.Text = status.TimeTaken.ToString() + " (UTC)"; lblBatteryStatActual.Text = (status.BatteryPercentage * 100.0d).ToString() + "%"; lblBatteryTempActual.Text = status.BatteryTemp + "°C"; lblIsPluggedInActual.Text = status.IsCharging ? "Yes" : "No"; } } else { Response.Redirect("Unauthorized.aspx"); } }
public bool UpdateHitchBotLocation(int HitchBotID, double Latitude, double Longitude, double Altitude, float Accuracy, float Velocity, string TakenTime) { DateTime StartTimeReal = DateTime.ParseExact(TakenTime, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); using (var db = new Models.Database()) { var hitchBOT = db.hitchBOTs.Include(l => l.Locations).First(h => h.ID == HitchBotID); var location = new Location(); location.Latitude = Latitude; location.Longitude = Longitude; location.Altitude = Altitude; location.Accuracy = Accuracy; location.Velocity = Velocity; location.TakenTime = StartTimeReal; location.TimeAdded = DateTime.UtcNow; location.HitchBOT = hitchBOT; db.Locations.Add(location); db.SaveChanges(); hitchBOT.Locations.Add(location); db.SaveChanges(); } return true; }
public static string GetWeatherTweet(Models.Database_Excluded.Weather Weather, int HitchBotID) { string output = string.Empty; using (var db = new Models.Database()) { var CleverScriptForHitchBOT = db.CleverScriptAPIkeys.Where(cs => cs.HitchBOT.ID == HitchBotID); var CleverScriptKey = CleverScriptForHitchBOT.First(cs => cs.Description == weatherKey); string lastCS = string.Empty; foreach (string URLinput in Weather.GetIterator()) { NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); queryString["key"] = CleverScriptKey.APIkey; queryString["input"] = URLinput; if (!String.IsNullOrEmpty(lastCS)) queryString["cs"] = lastCS; dynamic json = WebHelper.GetJSON(WebHelper.GetRequest(testURl + queryString.ToString())); lastCS = json["cs"].ToString(); output = json["output"]; } } return HttpUtility.HtmlDecode(output).Replace("8b8", ":"); }
public HttpResponseMessage GetGoogleMapsRoute(int HitchBotID) { using (var db = new Models.Database()) { var response = Request.CreateResponse(HttpStatusCode.Moved); var mapsURL = db.StaticMaps.Where(sm => sm.HitchBot.ID == HitchBotID); if (mapsURL.Count() > 0) { var lastGenerated = mapsURL.OrderByDescending(l => l.TimeGenerated).First(); if (DateTime.UtcNow - lastGenerated.TimeGenerated > TimeSpan.FromHours(0.5)) { response.Headers.Location = new Uri(GetStaticMapURL(Helpers.LocationHelper.GetEncodedPolyLine(HitchBotID))); } else response.Headers.Location = new Uri(GetStaticMapURL(lastGenerated.URL)); } else response.Headers.Location = new Uri(GetStaticMapURL(Helpers.LocationHelper.GetEncodedPolyLine(HitchBotID))); return response; } }
protected void Build_Javascript_Coords() { using (var db = new Models.Database()) { var user = (Models.Password)Session["New"]; var hitchbot = db.hitchBOTs.Include(l => l.WikipediaEntries.Select(i => i.TargetLocation)).First(l => l.ID == user.hitchBOT.ID); var locations = hitchbot.WikipediaEntries.Where(l => l.TargetLocation != null).ToList(); StringBuilder buildOutput = new StringBuilder(); buildOutput.Append(@"<script type=""text/javascript"">"); buildOutput.Append(@"var coords = ["); buildOutput.Append(string.Join(",\n", locations.Select(coord => string.Format("{{ coord : new google.maps.LatLng({0},{1}), radius : {2} }}", coord.TargetLocation.Latitude, coord.TargetLocation.Longitude, coord.RadiusKM)).ToList())); buildOutput.Append(@"];"); buildOutput.Append(@"</script>"); coordsOutput.Text = buildOutput.ToString(); } }
public static async void UploadImageAndAddToDb(int hbID, DateTime TimeTaken, string localFileDirectory, string fileName) { Task<string> publicURL = UploadImageAndGetPublicUrl(localFileDirectory, fileName); using (var db = new Models.Database()) { var hb = db.hitchBOTs.Include(l => l.Locations).FirstOrDefault(l => l.ID == hbID); var location = hb.Locations.OrderByDescending(l => l.TakenTime).FirstOrDefault(); var image = new Models.Image() { HitchBOT = hb, Location = location, url = await publicURL, TimeAdded = DateTime.UtcNow, TimeTaken = TimeTaken }; db.Images.Add(image); db.SaveChanges(); } }
public ApplicationController() { ViewFactory.getViewModel(this, "logInViewModel"); Models.Database database = new Models.Database(); }
protected void buttonSubmit_Click(object sender, EventArgs e) { try { var wikiEntry = inputWiki1.InnerText; var radius = inputRadiusValue.Value; var name = inputName.Value; var lat = inputLat.Value; var lng = inputLong.Value; double? radiusActual = null; double latActual; double lngActual; using (var db = new Models.Database()) { var user = (Models.Password)Session["New"]; var hitchbot = db.hitchBOTs.Include(l => l.WikipediaEntries).First(l => l.ID == user.hitchBOT.ID); Models.Location location = null; if (LocationCheckBox.Checked) { /* nullable double parse code borrowed from http://stackoverflow.com/questions/3390750/how-to-use-int-tryparse-with-nullable-int */ double tmp; if (!double.TryParse(radius, out tmp)) { setErrorMessage("Selected Radius is not valid!"); return; } radiusActual = tmp; if (!double.TryParse(lat, out latActual)) { setErrorMessage("Latitude is not valid number!"); return; } if (!double.TryParse(lng, out lngActual)) { setErrorMessage("Longitude is not valid number!"); return; } location = new Models.Location { Latitude = latActual, Longitude = lngActual, TimeAdded = DateTime.UtcNow, TakenTime = DateTime.UtcNow }; db.Locations.Add(location); db.SaveChanges(); } var wiki = new Models.WikipediaEntry { TargetLocation = location, WikipediaText = wikiEntry, EntryName = name, RadiusKM = radiusActual, HitchBot = hitchbot, TimeAdded = DateTime.UtcNow }; db.WikipediaEntries.Add(wiki); db.SaveChanges(); } Response.Redirect("AddTargetSuccess.aspx"); } catch { setErrorMessage("An unknown error occurred. let the sys admin know you saw this message."); } }
private void Button_Remove_Image(object sender, System.EventArgs e) { Button b = (Button)sender; using (var db = new Models.Database()) { int ID = int.Parse(b.CommandArgument); var img = db.Images.First(i => i.ID == ID); img.TimeDenied = DateTime.UtcNow; db.Images.Attach(img); db.ChangeTracker.DetectChanges(); db.SaveChanges(); } Response.Redirect("ViewImages.aspx", true); }
protected void Page_Load(object sender, EventArgs e) { if (Session["New"] != null) { var user = (Models.Password)Session["New"]; using (var db = new Models.Database()) { int hitchBOTid = user.hitchBOT.ID; var imgs = db.Images.Include(i => i.HitchBOT).Where(i => i.HitchBOT.ID == hitchBOTid && (i.TimeApproved == null && i.TimeDenied == null) && DbFunctions.DiffDays(i.TimeTaken, DateTime.UtcNow) <= 1).OrderBy(i => i.TimeTaken).ToList(); if (imgs.Count == 0) Label1.Text = "No recent images! Uh oh!"; TableRow tr = new TableRow(); for (int i = 0; i < imgs.Count; i++) { var img = imgs[i]; Table innerTable = new Table(); TableRow upperRow = new TableRow(); TableRow imageRow = new TableRow(); TableCell upper = new TableCell(); Image newImage = new Image(); newImage.ImageUrl = "http://imgur.com/" + img.url + ".jpg"; newImage.Width = 700; newImage.ImageAlign = ImageAlign.Right; newImage.Style.Add("transform", "rotate(90deg)"); newImage.Style.Add("margin-top", "25px"); TableCell imageCell = new TableCell(); imageCell.Controls.Add(newImage); imageRow.Cells.Add(imageCell); Button myButton2 = new Button(); myButton2.CommandArgument = img.ID.ToString(); myButton2.Text = "Save"; myButton2.Click += this.Button_Save_Image; upper.Controls.Add(myButton2); Button myButton1 = new Button(); myButton1.CommandArgument = img.ID.ToString(); myButton1.Text = "Remove"; myButton1.Click += this.Button_Remove_Image; upper.Controls.Add(myButton1); Label myLabel = new Label(); myLabel.Text = " Time Taken: " + img.TimeTaken.ToString() + " (UTC)"; upper.Controls.Add(myLabel); upperRow.Controls.Add(upper); upperRow.Height = 105; upperRow.VerticalAlign = VerticalAlign.Top; innerTable.Rows.Add(upperRow); innerTable.Rows.Add(imageRow); TableCell tc1 = new TableCell(); tc1.Controls.Add(innerTable); tc1.VerticalAlign = VerticalAlign.Top; tc1.Height = newImage.Width; tc1.Height = Unit.Parse((newImage.Width.Value + 60).ToString(), System.Globalization.CultureInfo.CurrentCulture); tc1.BorderStyle = BorderStyle.Solid; tr.Cells.Add(tc1); if (tr.Cells.Count >= 2) { tableViewImage.Rows.Add(tr); tr = new TableRow(); } } if (tr.Cells.Count == 1) { tableViewImage.Rows.Add(tr); } } } else { Response.Redirect("Unauthorized.aspx"); } }
public bool UpdateHitchBotLocationMin(string HitchBotID, string Latitude, string Longitude, string TakenTime) { DateTime StartTimeReal = DateTime.ParseExact(TakenTime, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); int newLocationID; int hitchBotID; using (var db = new Models.Database()) { hitchBotID = int.Parse(HitchBotID); double LatDouble = double.Parse(Latitude); double LongDouble = double.Parse(Longitude); var hitchBOT = db.hitchBOTs.Include(h => h.Locations).First(h => h.ID == hitchBotID); var location = new Location() { Latitude = LatDouble, Longitude = LongDouble, TakenTime = StartTimeReal, TimeAdded = DateTime.UtcNow, HitchBOT = hitchBOT }; db.Locations.Add(location); db.SaveChanges(); //hitchBOT.Locations.Add(location); //db.SaveChanges(); newLocationID = location.ID; } //Helpers.LocationHelper.CheckForTargetLocation(hitchBotID, newLocationID); return true; }
protected void Page_Load(object sender, EventArgs e) { if (Session["New"] != null) { var user = (Models.Password)Session["New"]; using (var db = new Models.Database()) { int hitchBOTid = user.hitchBOT.ID; var imgs = db.Images.Include(i => i.HitchBOT).Where(i => i.HitchBOT.ID == hitchBOTid && (i.TimeDenied == null) && DbFunctions.DiffDays(i.TimeTaken, DateTime.UtcNow) <= 3).OrderBy(i => i.TimeTaken).ToList(); if (imgs.Count == 0) Label1.Text = "No recent images! Come back soon."; TableRow tr = new TableRow(); for (int i = 0; i < imgs.Count; i++) { var img = imgs[i]; Table innerTable = new Table(); TableRow upperRow = new TableRow(); TableRow imageRow = new TableRow(); TableCell upper = new TableCell(); Image newImage = new Image(); newImage.ImageUrl = img.url; newImage.Width = 400; newImage.ImageAlign = ImageAlign.Right; newImage.Style.Add("transform", "rotate(90deg)"); newImage.Style.Add("padding-top", "100px"); TableCell imageCell = new TableCell(); imageCell.Controls.Add(newImage); imageRow.Cells.Add(imageCell); Button myButton2 = new Button(); myButton2.CommandArgument = img.ID.ToString(); myButton2.Text = "Save"; myButton2.CssClass = "save_btn"; myButton2.Click += this.Button_Save_Image; upper.Controls.Add(myButton2); Button myButton1 = new Button(); myButton1.CommandArgument = img.ID.ToString(); myButton1.Text = "Remove"; myButton1.CssClass = "remove_btn"; myButton1.Click += this.Button_Remove_Image; upper.Controls.Add(myButton1); Label myLabel = new Label(); myLabel.Text = " <br> Time Taken: " + img.TimeTaken.ToString() + " (UTC)"; upper.Controls.Add(myLabel); upperRow.Controls.Add(upper); upperRow.VerticalAlign = VerticalAlign.Top; innerTable.Rows.Add(imageRow); innerTable.Rows.Add(upperRow); TableCell tc1 = new TableCell(); tc1.Controls.Add(innerTable); tc1.VerticalAlign = VerticalAlign.Top; tc1.Height = newImage.Width; tc1.CssClass = "table_block"; tr.Cells.Add(tc1); if (tr.Cells.Count >= 2) { tableViewImage.Rows.Add(tr); tr = new TableRow(); } } if (tr.Cells.Count == 1) { tableViewImage.Rows.Add(tr); } } } else { Response.Redirect("Unauthorized.aspx"); } }