//deletes office book in sharepoint Office Book List private async static void DeleteOfficeBook(OfficeBook officeBook) { Console.WriteLine("***************************"); Console.WriteLine("Delete an Office Book"); Console.WriteLine("***************************"); Console.WriteLine("Enter ID"); userItemId = Console.ReadLine(); var officeBookItem = _officeBooks.Where(b => b.SharePointItemId.Contains(userItemId)).FirstOrDefault(); if (officeBookItem == null) { Console.WriteLine($"Office Book with ID: {userItemId} doesn't exist."); return; } string listItemId = userItemId; bool result = await Sites.DeleteListItem(_groupId, _siteId, _listId, listItemId); if (result) { Console.WriteLine("Book Successfully Deleted"); await RetrieveListItemsFromSharePoint(officeBook); } else { Console.WriteLine("Book Not Deleted"); } }
private async static void AddBook() { var list = lists.Where(b => b.DisplayName.Contains("Books")).FirstOrDefault(); IDictionary <string, object> data = new Dictionary <string, object>(); Console.WriteLine("***************************"); Console.WriteLine("Add New Book"); Console.WriteLine("Enter Title"); string title = Console.ReadLine(); var officeBookItem = new OfficeBook(); officeBookItem.Title = title; officeBookItem.BookId = Guid.NewGuid(); var jsonString = JsonConvert.SerializeObject(officeBookItem); data = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonString); bool result = await Sites.CreateListItem(_groupId, _siteId, list.Id, data); if (result) { Console.WriteLine("Item Created"); await LoadBooks(); } else { Console.WriteLine("Item Not Created"); } }
private async static void AddListItem(object obj) { IDictionary <string, object> data = new Dictionary <string, object>(); string jsonString; if (obj.GetType() == typeof(OfficeBook)) { list = lists.Where(b => b.DisplayName.Contains("Books")).FirstOrDefault(); _listId = list.Id; Console.WriteLine("***************************"); Console.WriteLine($"Add New {list.DisplayName}"); Console.WriteLine("Enter Title"); string title = Console.ReadLine(); var officeBookItem = new OfficeBook(); officeBookItem.Title = title; officeBookItem.BookId = Guid.NewGuid(); jsonString = JsonConvert.SerializeObject(officeBookItem); data = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonString); } else if (obj.GetType() == typeof(OfficeItem)) { list = lists.Where(b => b.DisplayName.Contains("Items")).FirstOrDefault(); _listId = list.Id; Console.WriteLine($"Add New {list.DisplayName}"); Console.WriteLine("Enter Title"); string title = Console.ReadLine(); var officeItem = new OfficeItem(); officeItem.Title = title; officeItem.ItemId = Guid.NewGuid(); jsonString = JsonConvert.SerializeObject(officeItem); data = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonString); } bool result = await Sites.CreateListItem(_groupId, _siteId, _listId, data); if (result) { Console.WriteLine("Item Created"); await RetrieveListItemsFromSharePoint(obj); } else { Console.WriteLine("Item Not Created"); } }
private async static void UpdateOfficeBook(OfficeBook officeBook) { IDictionary <string, object> data = new Dictionary <string, object>(); Console.WriteLine("***************************"); Console.WriteLine("Update Office Book Details"); Console.WriteLine("***************************"); Console.WriteLine("Enter ID"); userItemId = Console.ReadLine(); var officeBookItem = _officeBooks.Where(b => b.SharePointItemId.Equals(userItemId)).FirstOrDefault(); if (officeBookItem == null) { Console.WriteLine($"Office Book with ID: {userItemId} doesn't exist."); return; } string listItemId = userItemId; Console.WriteLine("Enter Title"); string title = Console.ReadLine(); officeBookItem.Title = title; var jsonString = JsonConvert.SerializeObject(officeBookItem); data = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonString); bool result = await Sites.UpdateListItem(_groupId, _siteId, _listId, listItemId, data); if (result) { Console.WriteLine("Book Successfully Updated"); await RetrieveListItemsFromSharePoint(officeBook); } else { Console.WriteLine("Book Not Updated"); } }