So I am deeply confused. I have two tables, one is locations assignments which consists of: location id, type and type id. I also have a table called services, which consists of name, id , description and icon.
The idea is to say, get me back all 13 services, from that we create 13 checkboxes. then we say, check the location assignments table, if this services (based on type, id and location id) matches a service in that list, check the checkbox, else leave it unchecked.
What I ahve so far is:
public static IEnumerable<Constants.Assignable> getAllService(int id)
{
List<Constants.Assignable> assign = new List<Constants.Assignable>();
using (var db = new Context())
{
var serv = from s in db.Services
join la in db.LocationAssignments on s.id equals la.typeId into LocationAssignments
from la in LocationAssignments
where la.locationId == id && s.id == la.typeId && la.type == Constants.SERV
select s;
foreach(var s in serv)
{
assign.Add(new Constants.Assignable(){
id = s.id, name = s.name
});
}
return assign;
}
}
which returns me, currently, two services, when it should return me 13. So there is something wrong with my join.
from there we do:
<h3 class="muted">Services Nearby</h3>
IEnumerable<UFA.Location.Core.Constants.Assignable> ServicesNearby = UFALocationApp.Helpers.LocationHelper.QueryHelper.getAllServicesNearby(Model.id);
foreach (var servicenb in ServicesNearby)
{
<div class="control-group">
<label class="control-label" for="serviceNearBy">
@servicenb.name
</label>
<div class="controls">
<input type="checkbox" id="Locationservice" value="@servicenb.id" name="serviceNB" checked="@(servicenb.assigned ? "checked" : "")" />
</div>
</div>
}
which prints out the two check boxes that are, in this case checked. there should be 11 more that are unchecked.
What do I have to change in my query to say: get me all services and only check off the ones associated with this location?