I'm using service layer lattern, and my solution contains three projects:
In my controller In the UI-project I have the following code:
public ActionResult AddSpotifyAlbums(List<SpotifyAlbums> albums)
{
_profileService.AddSpotifyAlbums(albums);
return Json(new { data = albums });
}
SpotifyAlbums in List<SpotifyAlbums>
Is a Model in my UI project. It looks like this:
public class SpotifyAlbums
{
public string URI { get; set; }
public int profileId { get; set; }
}
As you can see, I'm using a service here, _profileService
, to call a method that handles the saving of the albums.
But the type of the albums Is SpotifyAlbums
. How should I do in my service when the model type of the albums is SpotifyAlbums
?
I have tried to create a identical model in my Service-project, but it doesn't work. I get the following error:
Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'System.Collections.Generic.List' to 'soundyladder.Service.Models.SpotifyAlbums'
You cannot arbitrarily assign objects of different types to one another. Even though you give them the same name, they are independent entities.
Assuming the Service and UI projects reference your Core project, you can define the SpotifyAlbums
class in your Core project and reference that class across your other layers.