/// <summary> /// Creates an event on the server. /// </summary> /// <param name="e">Event to create.</param> public bool CreateEvent(Event e) { var request = buildRequest("host", Method.POST); //And the body containing event-informatinon var body = new { Date = e.Date, Location = e.Location, Title = e.Title, Description = e.Description, SlotsTaken = 0, SlotsTotal = e.SlotsTotal }; request.AddBody(body); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { JsonValue jVal = System.Json.JsonValue.Parse(response.Content); e.Id = jVal["Id"]; return true; } else { parseErrorMessage(response); return false; } }
/// <summary> /// Cancels the registration to the specified event. /// </summary> public void CancelReg(Event e) { var request = buildRequest(string.Format("event/{0}", e.Id), Method.DELETE); //Add body to request var cancelBody = new { eventId = e.Id, userToken = userToken }; request.AddBody(cancelBody); executeAndParseResponse(request); }
/// <summary> /// A method for updating data when the finish button is pressed. /// </summary> protected override void UpdateData() { // Get all the info saved in the activity. var type = Activity.Intent.GetStringExtra("type"); var title = Activity.Intent.GetStringExtra("title"); var description = Activity.Intent.GetStringExtra("description"); var year = Activity.Intent.GetIntExtra("date year", 0); var month = Activity.Intent.GetIntExtra("date month", 0); var day = Activity.Intent.GetIntExtra("date day", 0); var hour = Activity.Intent.GetIntExtra("date hour", 0); var minut = Activity.Intent.GetIntExtra("date minutte", 0); var place = Activity.Intent.GetStringExtra("place"); var max = Activity.Intent.GetIntExtra("maxslots", 0); var taken = Activity.Intent.GetIntExtra("slotstaken", 0); var id = Activity.Intent.GetStringExtra("id"); // Creat the event based on the information. var @event = new Event() { Location = place, Date = new DateTimeOffset(year, month, day, hour, minut, 0, new TimeSpan(0)), Description = description, Id = id, SlotsTaken = taken, SlotsTotal = max, Title = title }; bool completed = false; // Check whether this is editing an allready existing event, or making a new one. if (type == "edit") completed = MainActivity.CIF.UpdateEvent(@event); else if (type == "new") completed = MainActivity.CIF.CreateEvent(@event); else throw new ArgumentException("type has to be either edit or new"); if (completed) { Back(); } else { // If an error occured, show message. var dialog = new Android.Support.V7.App.AlertDialog.Builder(Activity); dialog.SetMessage(Activity.Resources.GetString(Resource.String.message_error_event_update_event) + "\n" + MainActivity.CIF.LatestError); dialog.SetNegativeButton(Resource.String.ok, (s, earg) => { }); dialog.Show(); } }
/// <summary> /// Updates the event. /// </summary> /// <param name="e">Event to update</param> public bool UpdateEvent(Event e) { var request = buildRequest("host", Method.PUT); request.AddBody(new { Id = e.Id, Date = e.Date, Location = e.Location, Title = e.Title, Description = e.Description, SlotsTaken = e.SlotsTotal - e.SlotsTaken, SlotsTotal = e.SlotsTotal }); return executeAndParseResponse(request); }
/// <summary> /// Replies the offer. /// </summary> /// <param name="answer">If set to <c>true</c> the user wants to join.</param> /// <param name="e">Event which is being replied to.</param> public void ReplyOffer(bool answer, Event e) { RestRequest request; var str = string.Format("offer/{0}", e.Id); if (answer) { request = buildRequest(str, Method.POST); } else { request = buildRequest(str, Method.DELETE); } executeAndParseResponse(request); }
/// <summary> /// Deletes the given event. /// </summary> /// <param name="e">Event to delete.</param> public void DeleteEvent(Event e) { var request = buildRequest("host/" + e.Id, Method.DELETE); executeAndParseResponse(request); }
protected override void OnCreate(Bundle bundle) { Position = 3; base.OnCreate (bundle); var content = new LinearLayout(this); content.Orientation = Orientation.Vertical; var scroll = new ScrollView(this); scroll.AddView(content); Content.AddView(scroll); // Create all visible elements required to create event var titleTitle = new TextView(this); titleTitle.Text = "Event name"; var title = new EditText(this); title.Hint = "Title"; title.Id = 0x0001; var descriptionTitle = new TextView(this); descriptionTitle.Text = "Event Description"; var description = new EditText(this); description.Hint = "Description!"; description.Id = 0x0002; var locationTitle = new TextView(this); locationTitle.Text = "Location/Address"; var location = new EditText(this); location.Hint = "Location/Address"; location.Id = 0x0003; var guestsTitle = new TextView(this); guestsTitle.Text = "Guests"; var guests = new EditText(this); guests.Hint = "Number of guests"; guests.InputType = global::Android.Text.InputTypes.ClassNumber; guests.Id = 0x0004; var dateTitle = new TextView(this); dateTitle.Text = "Date"; var date = new DatePicker(this); date.DateTime = DateTime.Now; date.Id = 0x0005; var timeTitle = new TextView(this); timeTitle.Text = "Time"; var timePicker = new TimePicker(this); timePicker.Id = 0x0006; // Buttons for creating a new event or cancel. var createEventButton = new Button(this); createEventButton.Text = "Host Event"; createEventButton.Id = 0x0007; createEventButton.Click += (object sender, EventArgs e) => { // Check if all forms have been filled. if(String.IsNullOrEmpty(title.Text) || String.IsNullOrEmpty(description.Text) || String.IsNullOrEmpty(location.Text) || String.IsNullOrEmpty(guests.Text)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog alertDialog = builder.Create(); alertDialog.SetTitle("Empty fields"); alertDialog.SetMessage(String.Format("The following fields are empty:\n{0}{1}{2}{3}", String.IsNullOrEmpty(title.Text) ? "- No title\n" : "", String.IsNullOrEmpty(description.Text) ? "- No description\n" : "", String.IsNullOrEmpty(location.Text) ? "- No address\n" : "", String.IsNullOrEmpty(guests.Text) ? "- No guest limit" : "")); alertDialog.SetButton("OK", (s, ev) => alertDialog.Dismiss()); alertDialog.Show(); } else { DateTime @dateTime = new DateTime(date.DateTime.Year, date.DateTime.Month, date.DateTime.Day, (int) timePicker.CurrentHour, (int) timePicker.CurrentMinute, 0); Event @event = new Event(title.Text, @dateTime, location.Text, description.Text, int.Parse(guests.Text), 0); bool completed = MainActivity.CIF.CreateEvent(@event); if(completed) Finish(); else { var dialog = new AlertDialog.Builder(this); dialog.SetMessage("Sorry, could not create event:\n" + MainActivity.CIF.LatestError); dialog.Show(); } } }; var cancelButton = new Button(this); cancelButton.Text = "Cancel"; cancelButton.Id = 0x0008; cancelButton.Click += (object sender, EventArgs e) => Finish(); var buttonKeeper = new LinearLayout(this); buttonKeeper.Orientation = Orientation.Horizontal; buttonKeeper.AddView(cancelButton); buttonKeeper.AddView(createEventButton); // Build Activity Content content.AddView(titleTitle); content.AddView(title); content.AddView(descriptionTitle); content.AddView(description); content.AddView(locationTitle); content.AddView(location); content.AddView(guestsTitle); content.AddView(guests); content.AddView(dateTitle); content.AddView(date); content.AddView(timeTitle); content.AddView(timePicker); content.AddView(buttonKeeper); // Create your application here }