0

Currently i'm pulling data from an rest call into a model and passing it from my controller to view but now I want to add a new field but some of the data is in a database. So I created a new model, most of the fields data are going to be the rest calls data but the new fields need to be populated from a database using the id from the rest model. Should I add a call to the database in the new model in the constructor?

public class Unshipped
{

    public long Id { get; set; }
    public string Name { get; set; }
    public string State { get; set; }
    public DateTimeOffset? OrderDate { get; set; }
    public DateTimeOffset? DeliveryDate { get; set; }
    public string SiteName { get; set; }
    public string ShipStatus { get; set; }
    public string ShipWorksStatus { get; set; }

    public Unshipped(long id)
    {
       //method Call to db to get the values I need
       ShipWorksStatus = GetStatus(id);
    }

    public string GetStatus(id)
    {
       //code to return value or values
    }

}

Should this be done in the controller?

 public async Task<IActionResult> Index()
 {
     var channelAdvisorUnshipped = await Task.Run(() => GetUnshippedOrdersApiCallAsync());


     GetShipworksShipStatus(channelAdvisorUnshipped);

     return View(UnshippedOrdersList);
 }
zerodoc
  • 393
  • 1
  • 4
  • 16

0 Answers0