I'm creating api using ASP.NET Web API
I have a method in repository which adds worker to company. Here is the method:
public void AddToCompanyBy(Guid workerId, Guid companyId)
{
var worker = GetById(workerId);
var company = DbContext.Set<Company>().Find(companyId);
if (worker == null)
throw new Exception("This worker does not exist");
if (company == null)
throw new Exception("This company does not exist");
company.Workers.Add(worker);
}
And I have an ApiController action that invokes this method. Here is this action:
public IHttpActionResult AddToCompany(Guid workerId, Guid companyId)
{
try
{
UoW.Workers.AddToCompanyBy(workerId, companyId);
return Ok();
}
catch (Exception ex)
{
return BadRequest();
}
}
So my questions are: am I right returning response as OK or I have to choose another type for response? Should I also return entity? How do I have mark the action (PUT or PATCH or GET)?