How to bind DevExpress Mobile Chart - xamarin.android

public class DataItem {
public string Name { get; set; }
public double ValueTest { get; set; }
public BindingList<double> ValueTest22 { get; set; }
}
SeriesDataAdapter dataAdapter22 = new SeriesDataAdapter();
dataAdapter22.DataSource = dataItems;
dataAdapter22.ArgumentDataMember = "Name";
dataAdapter22.ValueDataMembers.Add(new ValueDataMember() { Type = DevExpress.XamarinForms.Charts.ValueType.Value, Member = "ValueTest22[0]" });
I have a model called DataItem and I want to bind this class to a chart. However, I want to bind the data to the first index to the property of bindingList type called ValueTest22.
I don't have much experience with the DevExpress framework.
Is it possible to bind as I asked?
enter image description here
The X-axis seems to be bound, but the Y-axis doesn't seem to be bound. It looks like you are getting data initialized to 0.

Related

Send an IQueryable of arbitrary type to a general method

The problem: I am trying to create a general method that will take in an IQueryable which can be many different types of data including custom. In this method I will be doing a sort depending on the type of IQueryable that is being passed in.
What I am doing is creating a custom class with the following:
public class sortObject
{
public String OrderParam { get; set; }
public int pageSize { get; set; }
public int pageIndex { get; set; }//This is what page the user is on
public IQueryable<dynamic> entity { get; set; }
}
I will pass in an IQueryable object to this object like so:
sortObject so = new sortObject();
so.entity = _context.userAcount.Select(x=>x);
...
The so.entity will be IQueryable<dynamic> but in the base section of the object (while in debugging) will be of type userAccount. I want the data in the base in order to run the search.
My issue is that I do not know what the IQueryable type is until run time since this is a general method. It can be of type user, or of type address etc, but the sorting will still work because I will pass in what I want to order this by in the sortObject.
How can I either get the base data or convert the IQueryable type at runtime?
I found that this works in the sort table method:
var entity = so.entity.AsQueryable().OrderBy("UserName");
var data = entity.Skip(so.pageSize*(so.pageIndex-1)).Take(so.pageSize);
I think what you want is a solution involving generics - try
public class sortObject<T>
{
public String OrderParam { get; set; }
public int pageSize { get; set; }
public int pageIndex { get; set; }//This is what page the user is on
public IQueryable<T> entity { get; set; }
}
This will allow you to declare a sortObject with an entity of whatever type you want the IQuerable to contain.
You can make your method be something like
public void DoSomething<T>(sortObject<T> input)
{
// input.entity is now of type T
}
and you can call
sortObject so = new sortObject<userAccount>();
so.entity = _context.userAcount.Select(x=>x);
DoSomething(so);

How to iterate through a ViewModel's properties in the controller

I have a ViewModel with a number of different properties (ie string, int, etc) that I need to iterate through in the controller. What is the best way to do this? Here is the ViewModel's defintion:
public class BankListViewModel
{
public int ID { get; set; }
public string BankName { get; set; }
public string EPURL { get; set; }
public string AssociatedTPMBD { get; set; }
public string Tier { get; set; }
public List<BankListAgentId> BankListAgentId { get; set; }
public List<BankListStateCode> BankListStateCode { get; set; }
}
I need to omit the two lists, however. Any ideas?
EDIT
The purpose of this process is to pass specific items of the view model into three separate objects. The view model was created to combine properties of three separate SQL tables/Models. I am now trying to divide them up appropriately and add the information to the relevant tables. Right now I'm simply going one by one like so:
BankListMaster banklistmaster = new BankListMaster();
banklistmaster.AssociatedTPMBD = viewmodel.AssociatedTPMBD;
banklistmaster.BankName = viewmodel.BankName;
Although it's not clear why you would need to iterate over the properties instead of just reading their vaules, you could accomplish this using reflection
var model = new BankListViewModel();
PropertyInfo[] properties = model.GetType().GetProperties();
foreach (var property in properties)
{
if (property.GetType() != typeof(List<BankListAgentId>))
{
//do your thing here
}
}

Building a DropDownList in the Model?

I have a service layer that exposes a method, which returns me a List, called GetStates.
public List<StateObject> GetStates()
My State Object is just a custom object I have created:
public class StateObject
{
public int stateId { get; set; }
public string description { get; set; }
public Boolean isDefault { get; set; }
}
In my models, I am trying to create a model that will be used for my display and modification screen of a task. One thing this will be used for is handling the display and selection of a Drop down box, which will give a list of States available for my Task. So, my model looks something like this (Removed properties we don't car about - it's a bit bigger than this:
public class TaskModifyModel
{
public int stateId { get; set; }
public string state { get; set; }
public SelectList states { get; private set; }
public TaskModifyModel()
{
states = new SelectList(
(new ReferenceService().GetStates()),
"stateId",
"description",
1);
}
}
So, stateId holds the selected state, state holds the text description of the selected state. In the constructor, I am attempting to create a states SelectList for the view... and populate it.
In the view, I then try to display the Drop Down List:
#Html.DropDownListFor(m=>m.stateId, new SelectList(Model.states, "stateId", "description", Model.priorityId))
This is failing, dismally.
DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'stateId'.
I have searched, and I thought I was doing this the right way, but the error says I am not.. clearly. :) Could someone guide me on why it's not working, and also, is this the right way to do things?
Edit:
After assistance below, it's now working. If I am creating a new task (taskId==0), then I have to get the default value of the dropdown, as stored in my database.... So, is this clean? This is my working constructor for the object:
public TaskModifyModel()
{
var referenceService = new ReferenceService();
var p = referenceService.GetPriorities();
var s = referenceService.GetStates();
var defaultP = (from a in p where a.isDefault select a).FirstOrDefault();
var defaultS = (from a in s where a.isDefault select a).FirstOrDefault();
priorities = new SelectList(
(p),
"priorityId",
"description"
);
priorityId = taskId == 0 ? defaultP.priorityId : priorityId;
states = new SelectList(
s,
"stateId",
"description");
stateId = taskId == 0 ? defaultS.stateId : stateId;
}
Is it OK?
Your public SelectList states { get; private set; } is already a SelectList so you don't need to cast it again in your View.
Try this instead:
#Html.DropDownListFor(m=>m.stateId, Model.states)
And in your ViewModel, remove the parameter "SelectedValue". The #Html.DropDownListFor will initialize the dropdown to the right value.
public class TaskModifyModel
{
public int stateId { get; set; }
public string state { get; set; }
public SelectList states { get; private set; }
public TaskModifyModel()
{
states = new SelectList(
(new ReferenceService().GetStates()),
"stateId",
"description");
}
}

How do I use AutoMapper with eager-loading and collections?

This statement returns a list of people and their addresses and phone numbers.
var listOfPeople = db.People.AsQueryable();
Now, I'd like to use AutoMapper to map the results of the above LINQ statement to a view model. The view model was created mainly to prevent some properties from being returned to the client / user.
How do I get AutoMapper to map the results, listOfPeople, to a view model composed of the base object, Person, and ICollections of Addresses and PhoneNunmbers? I don't have a problem mapping a single person to a single vm. I think I'm getting hung up on mapping a collection, listOfPeople, that contains a couple of collections within.
I'm using ASP.NET Web API 4, not MVC 4.
Here is the view model
public class BasicApiViewModel
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
public virtual ICollection<Phone> Phones { get; set; }
}
If I understood your question, there is no need to separately configure collection mappings, you just need to define mapping between classes (as you've already done), and collections will be handled automatically
AutoMapper only requires configuration of element types, not of any
array or list type that might be used. For example, we might have a
simple source and destination type:
public class Source
{
public int Value { get; set; }
}
public class Destination
{
public int Value { get; set; }
}
All the basic generic collection types are supported:
Mapper.CreateMap<Source, Destination>();
var sources = new[]
{
new Source { Value = 5 },
new Source { Value = 6 },
new Source { Value = 7 }
};
IEnumerable<Destination> ienumerableDest = Mapper.Map<Source[], IEnumerable<Destination>>(sources);
ICollection<Destination> icollectionDest = Mapper.Map<Source[], ICollection<Destination>>(sources);
IList<Destination> ilistDest = Mapper.Map<Source[], IList<Destination>>(sources);
List<Destination> listDest = Mapper.Map<Source[], List<Destination>>(sources);
Destination[] arrayDest = Mapper.Map<Source[], Destination[]>(sources);
Lists and arrays

MVC 4, Upshot entities cyclic references

I have a DbDataController which delivers a List of Equipment.
public IQueryable<BettrFit.Models.Equipment> GetEquipment() {
var q= DbContext.EquipmentSet.OrderBy(e => e.Name);
return q;
}
In my scaffolded view everything looks ok.
But the Equipment contains a HashSet member of EquipmentType. I want to show this type in my view and also be able to add data to the EquipmentType collection of Equipment (via a multiselect list).
But if I try to include the "EquipmentType" in my linq query it fails during serialisation.
public IQueryable<BettrFit.Models.Equipment> GetEquipment() {
var q= DbContext.EquipmentSet.Include("EquipmentType").OrderBy(e => e.Name);
return q;
}
"Object Graph for Type EquipmentType Contains Cycles and Cannot be Serialized if Reference Tracking is Disabled"
How can I switch on the "backtracking of references"?
Maybe the problem is that the EquipmentType is back-linking through a HashSet? But I do not .include("EquipmentType.Equipment") in my query. So that should be ok.
How is Upshot generating the model? I only find the EquipmentViewModel.js file but this does not contain any model members.
Here are my model classes:
public class Equipment
{
public Equipment()
{
this.Exercise = new HashSet<Exercise>();
this.EquipmentType = new HashSet<EquipmentType>();
this.UserDetails = new HashSet<UserDetails>();
}
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Picture { get; set; }
public string Link { get; set; }
public string Producer { get; set; }
public string Video { get; set; }
public virtual ICollection<EquipmentType> EquipmentType { get; set; }
public virtual ICollection<UserDetails> UserDetails { get; set; }
}
public class EquipmentType
{
public EquipmentType()
{
this.Equipment = new HashSet<Equipment>();
this.UserDetails = new HashSet<UserDetails>();
}
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<Equipment> Equipment { get; set; }
public virtual ICollection<UserDetails> UserDetails { get; set; }
}
try decorating one of the navigation properties with [IgnoreDataMember]
[IgnoreDataMember]
public virtual ICollection<Equipment> Equipment { get; set; }
The model generated by upshot can be found on the page itself. In your Index view you will see the UpshotContext HTML helper being used (given that you are using the latest SPA version), in which the dataSource and model type are specified.
When the page is then rendered in the browser, this helper code is replaced with the actual model definition. To see that, view the source code of your page in the browser and search for a <script> tag that starts with upshot.dataSources = upshot.dataSources || {};
Check here for more info about how upshot generates the client side model.
As for the "backtracking of references", I don't know :)
I figured out - partially how to solve the circular reference problem.
I just iterated over my queried collection (with Include() ) and set the backreferences to the parent to NULL. That worked for the serialisation issue which otherwise already breaks on the server.
The only problem now is the update of a data entity - its failing because the arrays of the referenced entitycollection are static...
To solve the cyclic backreference, you can use the IgnoreDataMember attribute. Or you can set the back reference to NULL before returning the data from the DbDataController
I posted a working solution to your problem in a different question, but using Entity Framework Code First.
https://stackoverflow.com/a/10010695/1226140
Here I show how to generate your client-side model manually, allowing to you to map the data however you please

Resources