I am working with MVC3 and entity framework
I have got a table with:
id – Day of the week – Muscle – amount of sets – Customer
This is one table… It’s just a simple little project.
But my problem is that I don’t know how to get the proper View to get.
**Monday Tuesday Wednesday Thursday Friday Saturday Sunday**
Muscle Muscle etc...
sets sets
What I think I should do…first getting the list of the days the customer (which he created) wants to workout
Model
fitnessday is an property which is connected with my database with datacontext.
so like
public class FitnessDay
{
public int id { get; set; }
public string dayoftheweek{ get; set; }
public string muscle{ get; set; }
public Nullable<int> sets{ get; set; }
public Nullable<int> customerId{ get; set; }
public virtual Customer Customers{ get; set; }
}
public class Customer
{
public Customer()
{
this.fitnessDay = new HashSet<fitnessDay>();
}
// Primitive properties
public int id { get; set; }
public string name{ get; set; }
public string lastname{ get; set; }
// Navigation properties
public virtual ICollection<fitnessDay> fitnessDay { get; set; }
}
–
private IList<fitnessDay> trainingList= null;
public IList<fitnessDay> Training()
{
string nameOfCustomer= "bob";
var Training1 = db.fitness.Where(c => c.Customer.name== nameOfCustomer);
trainingList= Training1.ToList();
return trainingList;
}
Controller
public ViewResult TrainingView()
{
var list = model.training();
return View(list);
}
view
Don't know how to show it here.
Can someone help me out get the day of the week and place the proper Muscle and set underneath it (there could be several muscles per day)
edit: new information added
This was created to display the periodic table, but it’s a great piece of ui
http://isotope.metafizzy.co/
It does require a fair amount of jquery knowledge but, again, it’s a great piece of ui a very adaptable.
That is, of course, if you’re looking for something a bit more that a calendar.
edit
Since jquery is really not your thing here’s what I think is a simple suggestion.
On the controller side, load all training sessions ORDER ASC (I don’t know how to work with Linq but surely it can be done). I’m also assuming that you know the BETWEEN dates of traings you’re querying.
So in the controller you’d aglomerate the dates like this:
this would get all the training’s in the same day together (I’ve heard that some people go the gym more that once a day, not sure if that’s true or not).
Now, you can have your view strongly type, so you change it to something like:
and don’t forget
<%@ Import %>the Trainingnamespaceand finally you view could be something like this:Obviously instead of repeating the same code for the entries you could create an extension method for the Html object.