Xamarin Shell Flyout created from database data - shell

I have app of lists and items in each list. The list and their items are stored in two tables. A list data would be like "Grocery" and the list items like "bananas" etc. You can add lists and items in the app. Right now I have a list content page that lists the list names. Tap one and you go to a content page of the items in that list. This works, but I want to populate the Shell flyout with the list names from a database query in the AppShell.xaml.cs file. I want to do something like this:
ShellSection shell_section = new ShellSection();
var lists = await SLOMBListDataStore.GetSLOMBListsAsync(true);
foreach (var list in lists)
{
shell_section.Title = list.ListName;
shell_section.Icon = "tab_feed.png";
shell_section.Items.Add(new ShellContent() { Content = new SLOMBListDataPage(new SLOMBListDataViewModel(list.id)) });
this.Items.Add(shell_section);
}
BindingContext = this;
This, by the way, does not work. Creating the entries works manually if I use shell_section1, shell_section2 etc, but then you have to hard code the lists. Is it possible to do what I want, create the flyout from the query data? Thanks

Try to put the initialization code into the for loop like:
var lists = await SLOMBListDataStore.GetSLOMBListsAsync(true);
foreach (var list in lists)
{
ShellSection shell_section = new ShellSection();
shell_section.Title = list.ListName;
shell_section.Icon = "tab_feed.png";
shell_section.Items.Add(new ShellContent() { Content = new SLOMBListDataPage(new SLOMBListDataViewModel(list.id)) });
this.Items.Add(shell_section);
}
You need a new instance for each record.

Related

How do I save multiple selections from List to EF Model?

I am trying to learn how to submit multiple selections from a list to the model created between two data models. I have tried the following:
var tag = context.TagInformation.Find(model.Tags[0]);
var newlyCreatedUser = context.Users.Find(user.Id);
newlyCreatedUser.TagInfo = new List<TagInformation>(0) { tag };
context.SaveChanges();
I have also tried the following:
var tags = new List<TagInformation>();
foreach (var tag in model.Tags)
{
var tag= context.TagInformation.Find(model.Tags[0]);
if (tag != null)
{
tags.Add(tag);
}
}
var newlyCreatedUser = context.Users.Find(user.Id);
newlyCreatedUser.TagInfo = tags;
context.SaveChanges();
I have searched on Google and tried to find what value I need to change here in order to save all selected values from model.Tags, but currently only the first selected value is saved. To my understanding, the [0] is causing it to only save the first selected tag. I need to automatically save any combination of selected tags from the List, regardless of how many tags are in the list.
I can see that all of the select tags are loaded during debugging, and the foreach statement gets passed through for each selected id, but still only saves the first tag selected in the list.
What must I change to obtain this result and where can I find documentation to help me understand? Thanks in advance.
var tag= context.TagInformation.Find(model.Tags[0]);
this line of code always select the first tag, you should do something like
var tag= context.TagInformation.Find(tag);

how to update observable collection group

I have implemented group observable collection like below.
Grouped Property
private ObservableCollection<Grouping<String, Request>> _groupedList = null;
public ObservableCollection<Grouping<String, Request>> GroupedList {
get {
return _groupedList;
}
set {
_groupedList = value;
RaisePropertyChanged(() => GroupedList);
}
}
Creating List
var list = new List<Request>();
var grouped = from Model in list
group Model by Model.Done into Group
select new Grouping<string, Request>(Group.Key, Group);
GroupedList = new ObservableCollection<Grouping<string, TModel>>(grouped);
Now i need to update one item in the list without reloading full list for performance.
i did tried like this , mylist.FirstOrDefault(i => i.Id== mymodel.Id); Not worked for me.
I need to pick that particular item and edit and update into the list again using linq or something but i stuck here for group observable collection no efficient details to do this., anybody having idea about this help please.
And finally i get updated single item, but i need to do that without
GroupedList = new ObservableCollection<Grouping<string, TModel>>(grouped);
Because everytime it create new list and bind into my view.Thats again big performance though.
Thanks in advance.
What I understand from your question is that you want to push an updated group without overwriting the entire ObservableCollection.
To do that:
var targetGroup = GroupedList.FirstOrDefault(i => i.Id == mymodel.Id);
var targetIndex = GroupedList.IndexOf(targetGroup);
var modifiedGroup = ... //Do whatever you want to do
GroupedList[targetIndex] = modifiedGroup;
This will trigger a 'replace' operation of the target grouping.

unable to get multiple entries in SelectEntries of DotNetZip

I'm trying to use DotNetZipLib-DevKit-v1.9 in my MVC3 Project to extract the files to a specific folder.
What i want is -- How to add multiple entries in zip.SelectEntries method.
Here is my code in controller action:
public ActionResult ExtractZip(string fileName, HttpPostedFileBase fileData)
{
string zipToUnpack = #"C:\Users\Public\Pictures\Sample Pictures\images.zip";
string unpackDirectory = System.IO.Path.GetTempPath();
using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
{
// here, we extract every entry, but we could extract conditionally
// based on entry name, size, date, checkbox status, etc.
var collections = zip1.SelectEntries("name=*.jpg;*.jpeg;*.png;*.gif;");//This shows `0` items in collections
foreach (var item in collections)
{
item.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}
}
return Json(true);
}
In this line var collections = zip1.SelectEntries("name=*.jpg;*.jpeg;*.png;*.gif;"); if i specify only single extension ,it works fine
ex:
var collections = zip1.SelectEntries("name=*.gif"); this works good
I've also seen SelectEntries method here, but it doesn't help though
How to add multiple entries ?
Finally i could answer my own question.
Inorder to select multiple entries we need to use OR and to select multiple entries use the following code:
var collections = zip1.SelectEntries("(name=*.jpg) OR (name=*.jpeg) OR (name=*.png) OR (name=*.gif)");
foreach (var item in collections)
{
item.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}

Pass a List of Series to SetSeries

I am using DotNet.Highcharts in conjunction with Visual Studio 2010. I have created an array of Series:
List<Series> allSeries = new List<Series>();
I then looped through a database and added several different Series. Then I created a Highchart and need to add the allSeries list to it. I have the code below that I used to create a Series one at a time. How can I take the allSeries list and pass it to SetSeries?
.SetSeries(new[]
{
new Series { Name = "Combiner 2", Data = new Data(myData2) },
new Series { Name = "Combiner 3", Data = new Data(myData3) }
});
if I am left to assume that the myData2 and myData3 objects are contained in or could be extracted from allSeries, then you should be able to do something like this:
.SetSeries(allSeries.Select(s=> new Series { Name = s.Name, Data = s.Data }));
EDIT:
If set series isn't looking for an IEnumerable<Series> but instead needs Object[] or Series[], then you could do this:
//casts series elements to object, then projects to array
.SetSeries(allSeries.Select(s=> (object)new Series { Name = s.Name, Data = s.Data }).ToArray());
or maybe this:
//projects series elements to array of series
.SetSeries(allSeries.Select(s=> new Series { Name = s.Name, Data = s.Data }).ToArray());
it all depends on what the method signature for SetSeries is.

How to Update one Sharepoint List (calendar) from Another (custom)?

As part of an EvenReceiver the itemAdded on a custom List (source) creates a Calendar entry in another List (target).
I now want to add an itemUpdated event so that when the the source List is updated the change is filtered through to the target List.
I am using c# in Visual Studio to develop the Event Receiver.
Can anyone please advise the best way to do this and how I create the link between the two Lists to ensure I can update from source to target?
Thank you.
You will have to udpate the target list yourself...
var sourceItem = this.properties.ListItem;
//you can use other properties to search for the item in the targetlist aswell
string query = string.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>{0}</Value></Eq></Where>", sourceItem.Title);
var spQuery = new SPQuery() { Query = query };
var foundItems = targetList.GetItems(spQuery);
if(foundItems.Count == 1)
{
var foundItem = foundItems[0];
//update the properties you want
foundItem["Property1"] = sourceItem["Property1"];
foundItem["Property2"] = sourceItem["Property2"];
foundItem["Property3"] = sourceItem["Property3"];
foundItem.Update();
}
Note that this piece of code is straight out of my head & untested ;-)

Resources