Example #1
0
        public ActionResult Create(String jsonRoute, String routeName, String routeCity, String routeDescription, String routeTags)
        {
            if (jsonRoute == null)
                throw new HttpException("No route was specified");
            if (routeName == null)
                throw new HttpException("No route name was specified");
            if (routeCity == null)
                throw new HttpException("No route city was specified");

            // Parse json to a list
            IList<RoutePointModel> temp = new JavaScriptSerializer().Deserialize<IList<RoutePointModel>>(jsonRoute);
            // The deserializer cannot directly create SqlGeography (Point) in RoutePointModel
            List<RoutePointModel> js = new List<RoutePointModel>();
            foreach (RoutePointModel r in temp)
            {
                js.Add(new RoutePointModel(r.latitude, r.longitude));
            }

            // Parse routeTags to a list of Strings
            IList<String> tags = new JavaScriptSerializer().Deserialize<IList<String>>(routeTags);

            // Make persistent
            RouteModel rm = new RouteModel(js);
            rm.userID       = (Guid)Membership.GetUser().ProviderUserKey;
            rm.city         = routeCity;
            rm.name         = routeName;
            rm.description  = routeDescription != null ? routeDescription : "";
            rm.heightmeters = 0;
            rm.setTags(new List<String>(tags));

            int routeID = RouteModel.insertRoute(rm);
            rm.routeID = routeID;

            return new EmptyResult();
        }
Example #2
0
        public PartialViewResult Favorite(int routeID, bool makeFavorite)
        {
            FavoriteModel fm = new FavoriteModel((Guid)Membership.GetUser().ProviderUserKey, routeID);
            if (makeFavorite)
                FavoriteModel.insertFavorite(fm);
            else
                FavoriteModel.deleteFavorite(fm);

            RouteModel rm = new RouteModel(routeID);
            return PartialView("Routes/_ListRoutesElement", rm);
        }
Example #3
0
 public PartialViewResult ListRouteElement(RouteModel rm)
 {
     return PartialView("Routes/_ListRoutesElement", rm);
 }
Example #4
0
        public ActionResult GMap(int? id)
        {
            if (id != null)
            {
                RouteModel rm = new RouteModel((int)id);
                return PartialView("Routes/_GMap", rm);
            }

            return PartialView("Routes/_GMap");
        }
Example #5
0
 public JsonResult RouteCoords(int id)
 {
     RouteModel rm = new RouteModel(id);
     return Json(rm.linestringToJson());
 }
Example #6
0
        public PartialViewResult RatingVote(int id, bool vote)
        {
            Guid userId = (Guid)Membership.GetUser().ProviderUserKey;
            RatingModel rm = new RatingModel(userId, id, vote);

            RatingModel.insertRating(rm);

            RouteModel routem = new RouteModel(id);
            return PartialView("Routes/_ListRoutesElement", routem);
        }
Example #7
0
        public static List<TagModel> getRouteTags(RouteModel rm)
        {
            List<Tag> tList = (from t in _db.Tags
                               join rt in _db.Routetags on t.Tag_ID equals rt.Tag_ID
                               where rt.Route_ID == rm.routeID
                               select t).ToList();

            List<TagModel> tmList = new List<TagModel>();
            foreach (Tag t in tList)
            {
                tmList.Add(new TagModel(t));
            }
            return tmList;
        }
Example #8
0
        public static int insertRoute(RouteModel rm)
        {
            // Create route tuple (meta data)
            Route r = new Route();
            r.User_ID = rm.userID;
            r.City = rm.city;
            r.Name = rm.name;
            r.Heightmeters = rm.heightmeters;
            r.Description = rm.description;
            r.ValidFrom = DateTime.Now;
            _db.Routes.InsertOnSubmit(r);
            _db.SubmitChanges();

            // Create event, that route was created
            RouteCreatedEvent rce = new RouteCreatedEvent(r);
            rce.save();

            // Add tags
            List<Tag> insTags = TagModel.insertTags(rm.tags);
            if (insTags != null)
            {

                List<Routetag> rtags = new List<Routetag>();
                foreach (Tag t in insTags)
                {
                    Routetag rt = new Routetag();
                    rt.Route_ID = r.RouteID;
                    rt.Tag_ID = t.Tag_ID;
                    rtags.Add(rt);
                }
                _db.Routetags.InsertAllOnSubmit(rtags);
                _db.SubmitChanges();
            }

            // Update inputted routemodel with id given by DB
            rm.routeID = r.RouteID;

            // Select the SPROC to use
            SqlConnection conn = new SqlConnection(_db.Connection.ConnectionString);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "InsertRouteLineString";
            cmd.CommandType = CommandType.StoredProcedure;

            // Add arguments to the SPROC
            SqlParameter param = new SqlParameter("@LINESTRING", SqlDbType.Udt);
            param.SqlDbType = SqlDbType.Udt;
            param.UdtTypeName = "geography";
            param.Value = rm.routeLineString;

            cmd.Parameters.Add(param);

            cmd.Parameters.Add(new SqlParameter("@ROUTEID", r.RouteID));

            cmd.ExecuteNonQuery();

            return r.RouteID;
        }