public HttpResponseMessage Get(string tenant_id) { List <CompanyContainer> nulledcompany = new List <CompanyContainer>(); var Companys = CompanyService.GetAll().Where(o => o.Owner == tenant_id); if (Companys == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "No content or wrong tenant id")); } else { foreach (Company c in Companys) { CompanyContainer cc = new CompanyContainer(); cc.CompanyID = c.CompanyID; cc.CompanyName = c.CompanyName; cc.Address = c.Address; cc.PhoneNumber = c.PhoneNumber; switch (c.Country) { case Countries.Tunisia: cc.Country = "Tunisia"; break; case Countries.France: cc.Country = "France"; break; case Countries.Belgium: cc.Country = "Belgium"; break; case Countries.UK: cc.Country = "UK"; break; case Countries.USA: cc.Country = "USA"; break; } nulledcompany.Add(cc); } return(Request.CreateResponse(HttpStatusCode.OK, nulledcompany)); } }
// GET: /Company/5?tenant-id public HttpResponseMessage Get(string tenant_id, int id) { Company c = CompanyService.GetById(id); if (c == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Incorrect company id")); } else if (c.Owner != tenant_id) { return(Request.CreateResponse(HttpStatusCode.Forbidden, "You are not allowed, check your tenant id")); } else { CompanyContainer cc = new CompanyContainer(); cc.CompanyID = c.CompanyID; cc.CompanyName = c.CompanyName; cc.Address = c.Address; cc.PhoneNumber = c.PhoneNumber; switch (c.Country) { case Countries.Tunisia: cc.Country = "Tunisia"; break; case Countries.France: cc.Country = "France"; break; case Countries.Belgium: cc.Country = "Belgium"; break; case Countries.UK: cc.Country = "UK"; break; case Countries.USA: cc.Country = "USA"; break; } return(Request.CreateResponse(HttpStatusCode.OK, cc)); } }