0

I am trying to find a good way to return either the Id or the entire newly created object when adding a new item to the context and saving in my repository. Is there a way to still do this with the way I have the functions split: one to add to the context, then a SaveAll?

Repository functions:

public Product AddProduct(Product product, string username)
{
    feedPostLike.CreatedDate = DateTime.UtcNow;
    feedPostLike.CreatedBy = username;

    _context.Add(product);
}

public bool SaveAll()
{
    return _context.SaveChanges() > 0;
}

The way I am using the repository in the controller:

var newProd = _repository.AddProduct(productToSave, "superadmin");
_repository.SaveAll();
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231

0 Answers0