I have got an MVC application in which the Domain Model (Data Model + Business Model) resides in a different class library. I am using an interface exposing some methods which must return data but not necessarily the entire representation of my domain objects.
My question is How should I return the data?
Should I create a kind of view models on the Business Model layer and then match them with my real view models on the main application (views-controllers-viewmodels
)?
Should I return this data as dynamic objects?
Should I return the entire domain object event I need a couple of properties only?
What is the best approach to follow?
This is an example to give a better idea about the situation:
//Domain Class
public class User
{
public string UserName { get; set; }
public int UserId { get; set; }
public string UserPassword{ get; set; }
public string FirstName{ get; set; }
public virtual ICollection<ApplicationUserTeam> ApplicationUserTeams
{
get { return _applicationUserTeams; }
set { _applicationUserTeams = value; }
}
}
public interface ITrackAttendance
{
dynamic GetUsersCompany(int CompanyId);
}
public class TrackAttendanceServices : ITrackAttendance
{
//Method returning a Dynamic Object???
public dynamic GetUsersCompany(int CompanyId)
{
using (var _ctx = new TrackAttendanceDb())
{
return _ctx.Users.Where(u => u.ApplicationUserTeams.FirstOrDefault().Team.CompanyId== CompanyId)
.Select(u =>
new
{
UserName = u.UserName,
UserId = u.Id,
userState = false
}).ToList();
}
}
}
Aucun commentaire:
Enregistrer un commentaire