//public async Task<UserEventList> GetUserEventList(int ID) //{ // UserEventList returnMe = null; // try // { // returnMe = await database.Table<UserEventList>().Where(d => d.ID == ID).FirstOrDefaultAsync(); // } // catch (Exception) // { // } // return returnMe; //} public async Task <UserEventList> AddUserEventList(string title) { bool nameExists = true; string newTitle = title; var countAdd = 0; while (nameExists) { nameExists = await database.Table <UserEventList>().Where(d => d.Title.ToLower() == newTitle.ToLower()).CountAsync() > 0; if (nameExists) { countAdd++; newTitle = title + $" ({countAdd})"; } } UserEventList newList = new UserEventList() { Title = newTitle }; await database.InsertAsync(newList); return(newList); }
public async Task <UserEventList> UpdateUserEventList(UserEventList list, bool withChildren = false) { bool nameExists = true; string newTitle = list.Title; var countAdd = 0; while (nameExists) { nameExists = await database.Table <UserEventList>().Where(d => d.Title.ToLower() == newTitle.ToLower() && d.ID != list.ID).CountAsync() > 0; if (nameExists) { countAdd++; newTitle = list.Title + $" ({countAdd})"; } } list.Title = newTitle; if (withChildren) { await database.InsertOrReplaceWithChildrenAsync(list); } else { await database.InsertOrReplaceAsync(list); } return(list); }
public async Task <UserEventList> InsertUpdateUserEventListAsync(UserEventList submitMe) { try { using (var client = new HttpClient()) { client.Timeout = new TimeSpan(0, 0, 15); //client.BaseAddress = new Uri(GlobalVars.UserEventListURL); var viewModelSubmit = new UserEventListViewModel { Title = submitMe.Title, Events = submitMe.Events.Select(d => d.ID).ToList(), ExternalAddress = submitMe.ExternalAddress, InternalSecret = submitMe.InternalSecret }; var serializedObject = JsonConvert.SerializeObject(viewModelSubmit); HttpContent content = new StringContent(serializedObject, Encoding.UTF8, "application/json"); var response = await client.PostAsync(GlobalVars.UserEventListURL + "/u", content); var responseStringContents = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(responseStringContents)) { try { var responseUserEventListReturnModel = JsonConvert.DeserializeObject <UserEventListReturnModel>(responseStringContents); var responseUserEventList = new UserEventList { ID = submitMe.ID, Events = submitMe.Events, ExternalAddress = responseUserEventListReturnModel.ExternalAddress, InternalSecret = responseUserEventListReturnModel.InternalSecret, Title = submitMe.Title, HasEventListChangedSinceSync = false }; return(responseUserEventList); } catch (Exception) { } } } } catch (Exception) { } return(null); }
public async Task <UserEventList> GetUserEventListWithChildrenAsync(UserEventList list) { return(await database.GetWithChildrenAsync <UserEventList>(list.ID)); }
public async Task DeleteUserEventList(UserEventList value) { await database.DeleteAsync(value); }
public async Task SetUserEventList(UserEventList value) { await database.InsertOrReplaceAsync(value); }
public async Task <UserEventList> UpdateUserEventListWithChildrenAsync(UserEventList list) { return(await UpdateUserEventList(list, true)); }
public async Task <UserEventList> InsertUpdateUserEventListAsync(UserEventList submitList) { return(await restService.InsertUpdateUserEventListAsync(submitList)); }