public int DodajPost(string tytul, string tresc, int status, string tagi, string opis) { using (LinqTodbBlogDataContext context = new LinqTodbBlogDataContext()) { Posty p = new Posty { tytul = tytul, tresc = tresc, status = status, data_dodania = DateTime.Now, data_modyfikacji = DateTime.Now, }; context.Posties.InsertOnSubmit(p); context.SubmitChanges(); Tagi t = new Tagi { id_posta = p.id, keywords = tagi, description = opis }; context.Tagis.InsertOnSubmit(t); context.SubmitChanges(); return p.id; } }
public void TagiTest() { AdministracjaController target = new AdministracjaController(); // TODO: Initialize to an appropriate value Tagi collection = null; // TODO: Initialize to an appropriate value ActionResult expected = null; // TODO: Initialize to an appropriate value ActionResult actual; actual = target.Tagi(collection); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
[HttpPost]//dodaj tagi public ActionResult Tagi(Tagi collection) { if (ModelState.IsValid) { blogDB.AddToTagi(collection); blogDB.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("DodajPost")); } }
public void DodajTag(int idPosta, string keywords, string desc) { using (LinqTodbBlogDataContext context = new LinqTodbBlogDataContext()) { Tagi t = new Tagi { id_posta = idPosta, keywords = keywords, description = desc }; context.Tagis.InsertOnSubmit(t); context.SubmitChanges(); } }
public ActionResult DodajPost(Post collection) { if (ModelState.IsValid) { DateTime now = DateTime.Now; now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); collection.data_dodania = now; blogDB.AddToPost(collection); blogDB.SaveChanges(); int post_id = blogDB.Post.Single(p => p.data_dodania == collection.data_dodania).id; Tagi tag = new Tagi(); tag.id_posta = post_id; return(View("Tagi", tag)); } else { ViewData["list"] = lista(); return(View(collection)); } }
public void AddTagsToRide(SQLiteConnection con, PP_testEntities context, Przejazdy_fs przejazd) { long time = 0; double vmax = 0; string ride = "SELECT START_TIMESTAMP, STOP_TIMESTAMP FROM ride"; using (SQLiteCommand cmd = new SQLiteCommand(ride, con)) { using (SQLiteDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { long stop = rdr.GetInt32(1); long start = rdr.GetInt32(0); time = stop - start; } } } double lastLatitude; double lastLongitude; long lastTimestamp; string ord = "SELECT * FROM location_data ORDER BY TIMESTAMP"; double sec; double minutes = 0.0; double speed = 0.0; double seconds = 0.0; double sum = 0.0; using (SQLiteCommand cmd = new SQLiteCommand(ord, con)) { using (SQLiteDataReader rdr = cmd.ExecuteReader()) { if (rdr.HasRows) { rdr.Read(); lastTimestamp = rdr.GetInt64(1); lastLatitude = Degrees2Radius(rdr.GetDouble(2)); lastLongitude = Degrees2Radius(rdr.GetDouble(3)); while (rdr.Read()) { long timestamp = rdr.GetInt32(1); double latitude = Degrees2Radius(rdr.GetDouble(2)); double longitude = Degrees2Radius(rdr.GetDouble(3)); long diffTime = timestamp - lastTimestamp; double diffLat = latitude - lastLatitude; double diffLng = longitude - lastLongitude; lastTimestamp = timestamp; lastLatitude = latitude; lastLongitude = longitude; double a = Math.Pow(Math.Sin(diffLat / 2), 2) + Math.Cos(lastLatitude) * Math.Cos(latitude) * Math.Pow(Math.Sin(diffLng / 2), 2); double b = 2 * Math.Asin(Math.Sqrt(a)); double dist = Math.Round(EarthRadiusInMeters * b, 2); double v = (dist / 1000) / ((double) diffTime / 1000 / 60 / 60); if (v > vmax) vmax = v; //Console.WriteLine(string.Format("{0}m - {1:0.00} km/h - {2}ms", dist, v, diffTime)); sum += dist; } sec = (double) time / 1000; minutes = sec / 60; speed = (sum / 1000) / (minutes / 60); seconds = (minutes - (int) minutes) * 60; //Console.WriteLine(string.Format("Distance: {0:0.000}km, Time: {1:0}h {2}min {3:0}s, Avg speed: {4:0.00}km/h, Max speed: {5:0.00}km/h", // (sum / 1000), (int)(minutes / 60), (int)minutes, seconds, speed, vmax)); } } } var tagVMax = new Tagi(); tagVMax.id_przejazdu = przejazd.id_przejazdu; tagVMax.skrot = Static.Tags.TagCode.MaxSpeed; tagVMax.komentarz = string.Format("{0:0.00}km/h", vmax); context.Tagis.Add(tagVMax); var tagAvgSpeed = new Tagi(); tagAvgSpeed.id_przejazdu = przejazd.id_przejazdu; tagAvgSpeed.skrot = Static.Tags.TagCode.AverageSpeed; tagAvgSpeed.komentarz = string.Format("{0:0.00}km/h", speed); context.Tagis.Add(tagAvgSpeed); var tagDist = new Tagi(); tagDist.id_przejazdu = przejazd.id_przejazdu; tagDist.skrot = Static.Tags.TagCode.Distance; tagDist.komentarz = string.Format("{0:0.000}km", sum/1000); context.Tagis.Add(tagDist); var tagTime = new Tagi(); tagTime.id_przejazdu = przejazd.id_przejazdu; tagTime.skrot = Static.Tags.TagCode.TotalTime; tagTime.komentarz = string.Format("{0:0}h {1}min {2:0}s", (int)(minutes / 60), (int)minutes, seconds); context.Tagis.Add(tagTime); }
public ActionResult Post(int year = 0, int month = 0, int day = 0, string id = "", int page = 0) { DateTime now, date2; id = id.Replace('_', ' '); if (month == 0 & day == 0 & year == 0) { return(View("Error")); } else if (month == 0 & day == 0) { now = new DateTime(year, 1, 1).AddYears(1); ViewData["data"] = String.Format("{0:yyyy}", now.AddYears(-1)); ViewData["akcja"] = "/" + year; date2 = now.AddYears(-1); } else if (day == 0) { now = new DateTime(year, month, 1).AddMonths(1); ViewData["data"] = String.Format("{0:yyyy-MM}", now.AddMonths(-1)); string m = Convert.ToString(month); if (m.Length == 1) { m = "0" + m; } ViewData["akcja"] = "/" + year + "/" + m; date2 = now.AddMonths(-1); } else { now = new DateTime(year, month, day).AddDays(1); ViewData["data"] = String.Format("{0:yyyy-MM-dd}", now.AddDays(-1)); string m = Convert.ToString(month); string d = Convert.ToString(day); if (m.Length == 1) { m = "0" + m; } if (d.Length == 1) { d = "0" + d; } ViewData["akcja"] = "/" + year + "/" + m + "/" + d; date2 = now.AddDays(-1); } if (id == "") { var posty = from posts in blogDB.Post where posts.data_dodania <now& posts.data_dodania> date2 & posts.status == 0 orderby posts.data_dodania select posts; var strPost = new PaginatedList <Post>(posty, page, pageSize); if (posty.Count() == 0) { ViewData["komunikat"] = "Brak postów w tym dniu."; } return(View(strPost)); } else { var post = from posts in blogDB.Post where posts.data_dodania <now& posts.data_dodania> date2 & posts.tytul.Equals(id) & posts.status == 0 orderby posts.data_dodania select posts; var strPost = new PaginatedList <Post>(post, page, pageSize); if (strPost.Count != 1) { return(View(strPost)); } else { int id_posta = strPost[0].id; Tagi Tagi = blogDB.Tagi.Single(t => t.id_posta == id_posta); List <string> lista_t = new List <string>(); int j = 0, k = 0; for (int i = 0; i < Tagi.keywords.Length; i++) { if (Tagi.keywords[i] == ',') { lista_t.Add(Tagi.keywords.Substring(j, k).TrimStart(' ')); j = i; j++; k = -1; } k++; } lista_t.Add(Tagi.keywords.Substring(j).TrimStart(' ')); ViewData["tagi"] = lista_t; // ViewData["description"] = Tagi.description; return(View("ViewPost", strPost[0])); } } }