예제 #1
0
        protected bool AddEvent(EventModel model, string eventId)
        {
            MySqlConnection connection = connectionModel.connection;
            MySqlCommand cmd;

            connection.Open();
            try
            {
                cmd = connection.CreateCommand();
                cmd.CommandText = "INSERT INTO EventsInfo(id, title, descr, location, eventTime, lon, lat, category, visibility, restriction) " +
                                  "Values(@id, @title, @description, @location, @eventTime, @lon, @lat, @category, @visibility, @restriction)";
                cmd.Parameters.AddWithValue("id",eventId);
                cmd.Parameters.AddWithValue("title", model.mTitle);
                cmd.Parameters.AddWithValue("description", model.mDescription);
                cmd.Parameters.AddWithValue("location", model.mLocation);
                cmd.Parameters.AddWithValue("eventTime", model.mDate);
                cmd.Parameters.AddWithValue("lon", model.mCoords[0]);
                cmd.Parameters.AddWithValue("lat", model.mCoords[1]);
                cmd.Parameters.AddWithValue("category", model.mCategory);
                cmd.Parameters.AddWithValue("visibility", model.mVisibility);
                cmd.Parameters.AddWithValue("restriction", model.mRestriction);

                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Debug.Write(TAG + ": failed to insert into database. Error: " + e.Message+"\n");
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                    connection.Close();
            }
            return true;
        }
예제 #2
0
        public JsonResult CreateEvent(
                            string title, 
                            string description, 
                            string category, 
                            string location, 
                            float[] coords, 
                            string date, 
                            string restriction,
                            string visibility )
        {
            Debug.Write("" + Directory.GetCurrentDirectory()+ "\n");

            EventModel model = new EventModel(title, description,category,location,coords,date,restriction,visibility);
            string eventId =  GetEventId(); // get event id for the current event
            // error handling
            if (eventId == "error") return Json(new { error = "Falied to read event id" }); // if event id could not be fetched
            if (eventId == "write to file failure") return Json(new { error = "Falied to write event id to the file" });
            Debug.Write(TAG + ": creating event...\n");

            bool result = AddEvent(model, eventId); // try to add event to db
            if (!result) return Json(new { error = "Falied to add event to db" });

            else
            {

                return Json(new
                {
                    title = model.mTitle,
                    description = model.mDescription,
                    category = model.mCategory,
                    location = model.mLocation,
                    coords = model.mCoords,
                    date = model.mDate,
                    restriction = model.mRestriction,
                    visibility = model.mVisibility
                });
            }
        }