public IHttpActionResult Post(Ad ad) { var LastAddressID = addressRepo.GetAll().Max(x => x.AddressId); var thisAddress = addressRepo.GetAll().Where(x => x.AddressId == LastAddressID).FirstOrDefault(); ad.UserId = thisAddress.UserId; ad.SpecId = specificationRepo.GetAll().Max(x => x.SpecId); ad.AddressId = addressRepo.GetAll().Max(x => x.AddressId); adRepo.Insert(ad); string uri = Url.Link("GetAdById", new { id = ad.AdId }); return(Created(uri, ad)); }