public async Task <IActionResult> Edit(int id, [Bind("Id,Name,HackerrankUsername,LabScore,HackerrankScore")] LeaderboardRow leaderboardRow) { if (id != leaderboardRow.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(leaderboardRow); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LeaderboardRowExists(leaderboardRow.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(leaderboardRow)); }
public async Task <ContentResult> Check(CheckViewModel viewModel) { if (!ModelState.IsValid || viewModel == null) { return(Content("Make sure you have filled up the fields")); } string url = viewModel.Url; var content = new FormUrlEncodedContent(new Dictionary <string, string>() { { "num_red_wool", "1" }, { "num_green_wool", "1" }, { "num_blue_wool", "1" }, }); var uriB = new UriBuilder(url); uriB.Path = "/request_price"; using var httpResponse = await _httpClient.PostAsync(uriB.Uri, content); httpResponse.EnsureSuccessStatusCode(); CheckPriceResponse checkPriceResponse = JsonConvert.DeserializeObject <CheckPriceResponse>(await httpResponse.Content.ReadAsStringAsync()); if (checkPriceResponse != null && checkPriceResponse.Price == 111) { var leaderBoardRow = await _context.LeaderboardRow .FirstOrDefaultAsync(m => m.HackerrankUsername == viewModel.Username); if (leaderBoardRow == null) { return(Content("Your application is working great, but are you sure your username is correct?")); } leaderBoardRow.LabScore = int.Parse(Configuration["Scores:Lab"]); try { _context.Update(leaderBoardRow); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(Content("Unknown Error occured")); } return(Content("Your Lab score has been updated to 200! Multiple submissions will not get you more marks btw")); } else { return(Content("Couldn't reach your application")); } }