Last active
February 25, 2022 21:42
-
-
Save jipengxiang/32dda180721ba5f624260ec35633668b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1) PLease upload your client side code to call talents API | |
(2) AWS url for web API if you have PUBLISHED your web api to AWS | |
or url to S3 image | |
(3) Sequence diagram for calling Stripe API | |
or calling global weather web service |
Lim Wen Hui 1646348
public class TalentsController : ApiController
{
static readonly TalentRepository repository = new TalentRepository();
[EnableCors(origins: "", headers: "", methods: "*")]
// download Microsoft.AspNet.Cors package library
[Route("api/talents")]
public IEnumerable GetAllTalents()
{
return repository.GetAll();
}
[Route("api/talents/{id:int}")]
public Talent GetTalent(int id)
{
Talent item = repository.Get(id);
if (item == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return item;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$.ajax({ type: 'GET', url: url, async: false, contentType: "application/json", jsonpCallback: callback, dataType: 'jsonp', tryCount: 0, retryLimit: 3, success: function (json) { console.dir('success'); }, error: function (xhr, textStatus, errorThrown ) { if (textStatus == 'timeout') { this.tryCount++; if (this.tryCount <= this.retryLimit) { sleep(1000); $.ajax(this); return; } return; } console.log(e.message); } });
2.1 Startup - Specify services used
public void ConfigureServices(IServiceCollection services) { services.AddDbContext<TalentDbContext>( options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddScoped<ITalentRepository, SqlTalentRepository>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
2.2 TalentDbContext - Create DB Context
`
public class TalentDbContext : DbContext
{
public TalentDbContext(DbContextOptions options) : base(options) {}
`
2.3 SqlTalentRepository - DB CRUD operations
`
public class SqlTalentRepository : ITalentRepository
{
private TalentDbContext _context;
`
3. AJAX Loading
$(document).ajaxStart(function () { $("#loading").show(); }).ajaxStop(function () { $("#loading").hide(); });