public int getLikeStatus(RegularUser user, Hike hike) { int resultID; try { SqlConnection connection = ManageDatabaseConnection("Open", "regular"); using (SqlCommand sqlCommand = new SqlCommand("getLikeStatus", connection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@UserId", user.UserId); sqlCommand.Parameters.AddWithValue("@HikeId", hike.HikeId); var returnParameter = sqlCommand.Parameters.Add("@ReturnVal", SqlDbType.Int); returnParameter.Direction = ParameterDirection.ReturnValue; sqlCommand.ExecuteNonQuery(); resultID = Convert.ToInt32(returnParameter.Value); } ManageDatabaseConnection("Close", "regular"); } catch (SqlException sqlException) { throw sqlException; } //Debug.WriteLine(resultID); return(resultID); }
public async Task <IActionResult> Edit(int id, [Bind("Id,HikeName,Path")] Hike hike) { if (id != hike.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(hike); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HikeExists(hike.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Path"] = new SelectList(_context.Paths, "Id", "Id", hike.Path); return(View(hike)); }
protected void addPoint(object sender, EventArgs e) { List <string> errorList = new List <string>(); errorList = validateAddPointInput(); if (!errorList.Any()) { Hike hike = (Hike)Session["HIKE"]; Point point = new Point(); point.Longitud = double.Parse(tb_longitud.Text, System.Globalization.CultureInfo.InvariantCulture); point.Latitud = double.Parse(tb_latitud.Text, System.Globalization.CultureInfo.InvariantCulture); point.Comment = tb_add_commentary.Text; if (imageupload.HasFile) { point.Image = imageupload.FileBytes; } else { point.Image = null; } point.Pos = hike.Route.ListOfPoints.Count; hike.Route.ListOfPoints.Add(point); Session["HIKE"] = hike; DisplayRoute(); } else { outputAddPointErrors(errorList); } }
protected void InitHike(object sender, EventArgs e) { List <string> errorList = new List <string>(); errorList = validateInitInput(); if (!errorList.Any()) { Hike hike = new Hike(); hike.NameOfLocation = tb_init_name.Text; hike.Province = dd_init_province.SelectedItem.Text; hike.Canton = dd_init_canton.SelectedItem.Text; hike.District = dd_init_district.SelectedItem.Text; hike.Details = tb_init_details.Text; hike.Longitud = double.Parse(tb_init_longitud.Text, System.Globalization.CultureInfo.InvariantCulture); hike.Latitud = double.Parse(tb_init_latitud.Text, System.Globalization.CultureInfo.InvariantCulture); hike.HikeType = dd_init_hiketype.SelectedItem.Text; hike.Difficulty = dd_init_difficultylevel.SelectedItem.Text; if (imageupload.HasFile) { hike.Image = imageupload.FileBytes; } else { hike.Image = null; } hike.SameHike = false; Session["HIKE"] = hike; Response.Redirect("NewHike.aspx"); } else { outputInitErrors(errorList); } }
public Tuple <int, string> removeLike(RegularUser user, Hike hike) { int id; string message; switch (likeData.RemoveLike(user, hike)) { case 0: id = 1; message = "Has removido tu like de esta caminata!"; break; case 1: id = 2; message = "No se le puede remover un like a la caminata que no le has dado like."; break; default: id = 2; message = "Error al agregar un like. Contacte a un administrador"; break; } Tuple <int, string> n = new Tuple <int, string>(id, message); return(n); }
public Hike loadHikeInfo(Hike hike) { try { SqlConnection connection = ManageDatabaseConnection("Open", "regular"); using (SqlCommand sqlCommand = new SqlCommand("getHikeInfo", connection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@idCaminata", hike.HikeId); using (SqlDataReader sqlReader = sqlCommand.ExecuteReader()) { if (sqlReader.Read()) { hike.NameOfLocation = sqlReader["nombreDelLugar"].ToString(); hike.Province = sqlReader["provincia"].ToString(); hike.Canton = sqlReader["canton"].ToString(); hike.District = sqlReader["distrito"].ToString(); hike.Details = sqlReader["detalle"].ToString(); hike.Latitud = sqlReader.GetDouble(5); hike.Longitud = sqlReader.GetDouble(6); } } } ManageDatabaseConnection("Close", "regular"); } catch (SqlException sqlException) { throw sqlException; } return(hike); }
protected void Edit(object sender, EventArgs e) { Hike hike = (Hike)Session["HIKE"]; Point point = (Point)Session["POINT"]; foreach (Point p in hike.Route.ListOfPoints) { if (p.PointId == point.PointId) { p.Comment = tb_add_commentary.Text; if (imageupload.HasFile) { p.Image = imageupload.FileBytes; } else { p.Image = null; } } } Session["POINT"] = null; Session["HIKE"] = hike; Response.Redirect("ExistingRoute.aspx"); }
private void UpdateStartDate() { ListAll(); var hike = new Hike(); do { hike = GetHike(); } while (hike.StartPoint == null); var input = ""; DateTime dDate; int i = 1; do { if (i > 1) { Console.WriteLine("Invalid input!", Color.Pink); } Console.WriteLine("\nEnter start date: (dd-mm-yy)"); input = Console.ReadLine(); i++; } while (!DateTime.TryParse(input, out dDate)); String.Format("{0:d/MM/yyyy}", dDate); hike.StartDate = dDate; Console.WriteLine("\nStart Date updated successfully!", Color.LightGreen); }
public ModernButton addButton(int userId, Hike h, int status) { ModernButton btn = new ModernButton(); //System.Web.UI.HtmlControls.HtmlGenericControl icon = //new System.Web.UI.HtmlControls.HtmlGenericControl("i"); string iconStr = ""; if (status == 1) { btn.Click += new System.EventHandler(UnLike); btn.CssClass = "btn btn-warning btn-circle btn-lg"; iconStr = "<i class=\"fa fa-times\"></i>"; //icon.Attributes["class"] = "fa fa-times"; } else { btn.Click += new System.EventHandler(Like); btn.CssClass = "btn btn-danger btn-circle btn-lg"; iconStr = "<i class=\"fa fa-heart\"></i>"; //icon.Attributes["class"] = "fa fa-heart"; } btn.Attributes["type"] = "button"; btn.ID = userId.ToString() + "_" + h.HikeId.ToString(); //btn.Controls.Add(icon); btn.Text = iconStr; return(btn); }
protected void Page_Load(object sender, EventArgs e) { if (Session["REG_USER"] == null) { Response.Redirect("SignInRegular.aspx"); } else if (Session["HIKE"] == null) { Response.Redirect("HikeLobby.aspx"); } if (!IsPostBack) { if (dd_qualitylevel.Items.Count == 0) { FillDropDownLists(); } RegularUser regularUser = (RegularUser)Session["REG_USER"]; LoggedInUsername.Text = regularUser.Account; Hike hike = (Hike)Session["HIKE"]; hike.Route = new Route(); hike.Route.ListOfPoints = new List <Point>(); Session["HIKE"] = hike; } DisplayRoute(); }
public IHttpActionResult PutHike(int id, Hike hike) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hike.Id) { return(BadRequest()); } db.Entry(hike).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!HikeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private void UpdateAverageDuration() { ListAll(); var hike = new Hike(); do { hike = GetHike(); } while (hike.StartPoint == null); string input; decimal value; int i = 1; do { if (i > 1) { Console.WriteLine("Invalid input!", Color.Pink); } Console.WriteLine("\nEnter average duration in hours: "); input = Console.ReadLine(); i++; } while (!decimal.TryParse(input, out value)); hike.AverageDuration = value; Console.WriteLine("\nAverage duration updated successfully!", Color.LightGreen); }
public List <Route> loadRouteInfo(Hike hike) { List <Route> listOfRoutes = new List <Route>(); try { SqlConnection connection = ManageDatabaseConnection("Open", "regular"); using (SqlCommand sqlCommand = new SqlCommand("getRouteInfo", connection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@idCaminata", hike.HikeId); using (SqlDataReader sqlReader = sqlCommand.ExecuteReader()) { while (sqlReader.Read()) { Route route = new Route(); route.RouteId = (int)sqlReader["idRuta"]; listOfRoutes.Add(route); } } } ManageDatabaseConnection("Close", "regular"); } catch (SqlException sqlException) { throw sqlException; } return(listOfRoutes); }
public void Play(Hike nowHike, Character subject) { int prg = nowHike.GetProgressChanger(); nowHike.SetProgressChanger(prg + progressChange); consequence.Play(nowHike, subject); }
protected void UnLike(object sender, EventArgs e) { LikeBusiness lb = new LikeBusiness(); ModernButton btn = (ModernButton)sender; string[] ids = btn.ID.Split('_'); RegularUser regularUser = new RegularUser(); regularUser.UserId = Int32.Parse(ids[0]); Hike hike = new Hike(); hike.HikeId = Int32.Parse(ids[1]); Tuple <int, string> t = new Tuple <int, string>(0, ""); t = lb.removeLike(regularUser, hike); Notification n = new Notification(); n.Type = t.Item1; n.Message = t.Item2; Session["NOTIFICATION"] = n; Response.Redirect("Notifications.aspx"); //Response.Redirect("Wall.aspx"); }
public Tuple <int, string> addLike(RegularUser user, Hike hike) { int id; string message; switch (likeData.InsertLike(user, hike)) { case 0: id = 1; message = "Le has dado like a la caminata!"; break; case 1: id = 2; message = "Ya le habias dado like a esta caminata!"; break; default: id = 2; message = "Error al agregar un like. Contacte a un administrador"; break; } Tuple <int, string> n = new Tuple <int, string>(id, message); return(n); }
public static void AddHikeSeedData() { Hike hike = new Hike() { TrailName = "Mary's Peak", Region = "Willamette Valley", //if I want to sort by region I think I need to add a new list? Description = "A wonderful example of a temperate rain forest " + "with views to the ocean from the top!" }; //UserReview review = new UserReview(); hikes.Add(hike); //hike.UserReviews.Add(review); hike = new Hike() { TrailName = "Cook's Ridge", Region = "Coast", //if I want to sort by region I think I need to add a new list? Description = "A mix of old growth and second growth in the Coast Range " + "near Cape Perpetua and Cumming's Creek." }; hikes.Add(hike); //hike.UserReviews.Add(review); hike = new Hike() { TrailName = "Fall Creek Falls", Region = "Southern Oregon", //if I want to sort by region I think I need to add a new list? Description = "This short shady trail follows a cascading creek, squeezes through a crack in a house-sized boulder, " + "and takes you to a double waterfall. A popular hike for kids." }; hikes.Add(hike); //hike.UserReviews.Add(review); }
//ShowHike -> Existing Route public Hike loadHike(Hike hike) { Hike h = new Hike(); h = hikeData.loadHikeInfo(hike.Route); h.Route.ListOfPoints = hikeData.loadPointInfo(h.Route); return(h); }
public ActionResult DeleteConfirmed(int id) { Hike hike = db.Hikes.Find(id); db.Hikes.Remove(hike); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(string name, string address, string type, string description) { Hike newHike = new Hike(name, address, type, description); newHike.Save(); List <Hike> allHikes = Hike.GetAll(); return(View("Index", allHikes)); }
public void InsertHikeWithExistingRoute(ref Hike hike, ref RegularUser regularUser) { int resultId = hikeData.InsertHikeWithHikeId(ref hike, ref regularUser); resultId = hikeData.InsertRouteWithRouteId(resultId, hike.Route.RouteId); foreach (Point p in hike.Route.ListOfPoints) { hikeData.InsertPointWithPointId(p, resultId); } }
public void InsertHike(ref Hike hike, ref RegularUser regularUser) { int resultId = hikeData.InsertHike(ref hike, ref regularUser); resultId = hikeData.InsertRoute(resultId); foreach (Point p in hike.Route.ListOfPoints) { hikeData.InsertPoint(p, resultId); } }
public LinkButton addLinkButton(Hike h) { LinkButton lbtn = new LinkButton(); lbtn.Click += new System.EventHandler(selectHike); lbtn.Text = "<i class=\"fa fa-circle-thin\"></i> " + h.NameOfLocation + " | Latitud: " + h.Latitud.ToString() + " Longitud: " + h.Longitud.ToString(); lbtn.CssClass = "list-group-item"; lbtn.ID = h.HikeId.ToString(); return(lbtn); }
public RedirectToActionResult AddHike(string trailName, string region, string description) { Hike hike = new Hike { TrailName = trailName, Region = region, Description = description }; repo.AddHike(hike); return(RedirectToAction("Hikes")); }
public ActionResult <List <Hike> > Get(int id) { Hike hike = hikes.Find(item => item.Id == id); if (hike == null) { return(NotFound($"No hike with id {id}")); } return(Ok(hike)); }
//Loads hikes of the user in the past month public List <Hike> LoadListOfHikes(RegularUser regularUser) { List <Hike> listOfHikes = new List <Hike>(); try { SqlConnection connection = ManageDatabaseConnection("Open", "regular"); using (SqlCommand sqlCommand = new SqlCommand("getHikesFromUser", connection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@UserId", regularUser.UserId); using (SqlDataReader sqlReader = sqlCommand.ExecuteReader()) { while (sqlReader.Read()) { Hike hike = new Hike(); hike.NameOfLocation = sqlReader["nombreDelLugar"].ToString(); hike.Province = sqlReader["provincia"].ToString(); hike.Canton = sqlReader["canton"].ToString(); hike.District = sqlReader["distrito"].ToString(); hike.Details = sqlReader["detalle"].ToString(); hike.Latitud = sqlReader.GetDouble(5); hike.Longitud = sqlReader.GetDouble(6); hike.DateTime = Convert.ToDateTime(sqlReader["fechaHora"]); hike.Quality = sqlReader["nivelDeCalidad"].ToString(); hike.Difficulty = sqlReader["nivelDeDificultad"].ToString(); hike.Price = sqlReader["nivelDePrecio"].ToString(); hike.HikeType = sqlReader["tipoDeCaminata"].ToString(); if (Convert.IsDBNull(sqlReader["fotografia"])) { hike.Image = null; } else { hike.Image = (byte[])sqlReader["fotografia"]; } hike.Comment = sqlReader["comentario"].ToString(); hike.HikeId = (int)sqlReader["idUsuarioPorCaminata"]; hike.Route = new Route(); hike.Route.RouteId = (int)sqlReader["idRutaPorUPC"]; listOfHikes.Add(hike); } } } ManageDatabaseConnection("Close", "regular"); } catch (SqlException sqlException) { throw sqlException; } return(listOfHikes); }
protected void selectHike(object sender, EventArgs e) { HikeBusiness hb = new HikeBusiness(); LinkButton lbtn = (LinkButton)sender; Hike hike = new Hike(); hike.HikeId = Int32.Parse(lbtn.ID); hike = hb.loadInfoOfListOfHikes(hike); Session["HIKE"] = hike; Response.Redirect("ShowHike.aspx"); }
public IHttpActionResult GetHike(int id) { Hike hike = db.Hikes.Find(id); if (hike == null) { return(NotFound()); } return(Ok(hike)); }
public bool getLikeStatus(RegularUser user, Hike hike) { if (likeData.getLikeStatus(user, hike) == 1) { return(true); } else { return(false); } }
public ActionResult <Hike> Delete(int id) { Hike matchingHike = hikes.Find(h => h.Id == id); if (matchingHike == null) { return(NotFound($"No hike with id {id}")); } hikes.Remove(matchingHike); return(NoContent()); }