public void Remove(Event eventToRemove) { try { Events?.Remove(eventToRemove); PersistenceFacade.DeleteEvent(eventToRemove); } catch (Exception) { throw new ArgumentException("Event doesnt exsist."); } }
public void AddEvent(Event newEvent) { try { PersistenceFacade.PostEventToDb(newEvent); Events?.Add(newEvent); } catch (Exception ex) { throw new ArgumentException(ex.Message); } }
public async void CreateEvent() { try { EventViewModel vm = EventVm; var dateTime = DateTimeConverter.DateTimeOffsetAndTimeSetToDateTime(vm.Date, vm.Time); Event newEvent = new Event(vm.Id, vm.Name, vm.Description, vm.Place, dateTime); EventVm.EventCatalog.AddEvent(newEvent); } catch (Exception ex) { await new MessageDialog(ex.Message).ShowAsync(); } }
public static async void DeleteEvent(Event dEvent) { HttpClientHandler handler = new HttpClientHandler(); handler.UseDefaultCredentials = true; using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(ServerUri); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { await client.DeleteAsync("api/Events/" + dEvent.Id); } catch (Exception ex) { throw new ArgumentException(ex.Message); } } }
//private static string jsonFileName = "EventsAsJson.dat"; //private static string xmlFileName = "EventsAsXml.dat"; public static async void PostEventToDb(Event events) { HttpClientHandler handler = new HttpClientHandler(); handler.UseDefaultCredentials = true; using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(ServerUri); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { await client.PostAsJsonAsync("api/Events", events); } catch (Exception ex) { await new MessageDialog(ex.Message).ShowAsync(); } } }
public void SetSelectedEvent(Event ev) { EventViewModel.SelectedEvent = ev; }
public void AddEvent(Event newEvent) { Events?.Add(newEvent); PersistenceFacade.PostEventToDb(newEvent); }