public async Task <IActionResult> ChampionAddOrUpdate([FromBody] ChampionAddEntity champion) { try { if (Request.Headers["API-KEY"] == apiKey) { if (!string.IsNullOrEmpty(champion.NAME)) { return(Ok(JsonConvert.SerializeObject(await _championsRepository.ChampionAddOrUpdate(champion)))); } else { return(BadRequest("Name is required!!!")); } } else { return(BadRequest("API-KEY not match")); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, "Service temporary and not available" + ex.Message)); } }
public async Task <ActionResult> Edit(int id, ChampionAddEntity championAdd) { try { ResultEntity result = new ResultEntity(); if (!String.IsNullOrEmpty(championAdd.NAME)) { if (championAdd.IMAGE_FILE != null) { string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "ChampionsImage"); string filePath = Path.Combine(uploadsFolder, championAdd.IMAGE_FILE.FileName); using (var fileSteam = new FileStream(filePath, FileMode.Create)) { championAdd.IMAGE_FILE.CopyTo(fileSteam); } championAdd.IMAGE_PATH = "/ChampionsImage/" + championAdd.IMAGE_FILE.FileName; } result = await _services.ChampionAddOrUpdate(championAdd); if (!result.RESULT) { return(RedirectToAction("ErrorPage")); } } return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction("ErrorPage")); } }
/// <summary> /// Auth API-KEY /// </summary> /// <param name="champion"></param> /// <returns></returns> public async Task <ResultEntity> ChampionAddOrUpdate(ChampionAddEntity champion) { ResultEntity result = new ResultEntity(); try { string reqBody = JsonConvert.SerializeObject(champion); HttpRequestMessage reqMessage = new HttpRequestMessage(HttpMethod.Post, url + "ChampionAddOrUpdate"); reqMessage.Headers.Add(configApiKey, apiKey); reqMessage.Content = new StringContent(reqBody, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.SendAsync(reqMessage); if (response.IsSuccessStatusCode) { var responseStr = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <ResultEntity>(responseStr); } else { result.RESULT = false; } } catch (Exception) { result.RESULT = false; } return(result); }
public async Task <ActionResult> Edit(int id) { try { AlreadyLoggedIn(); var roles = await _services.RoleList(); var lanes = await _services.RecommendedLaneList(); roles.roles.Insert(0, new RoleEntity { ID = 0, ROLE_NAME = "Select" }); lanes.Lanes.Insert(0, new RecommendedLaneEntity { ID = 0, LANE = "Select" }); ViewData["roles"] = roles.roles; ViewData["lanes"] = lanes.Lanes; var champions = await _services.GetChampion(id); ChampionAddEntity championsAdd = new ChampionAddEntity() { ID = champions.ID, NAME = champions.NAME, HISTORY = champions.HISTORY, STATS_DAMAGE = champions.STATS_DAMAGE, STATS_DIFFICULITY = champions.STATS_DIFFICULITY, STATS_TOUGHNESS = champions.STATS_TOUGHNESS, STATS_UTILITY = champions.STATS_UTILITY, ROLE_ID = roles.roles.Find(x => x.ROLE_NAME == champions.ROLE).ID, RECOMMENDED_LANE_ID = lanes.Lanes.Find(x => x.LANE == champions.LANE).ID, IMAGE_PATH = champions.IMAGE_PATH }; return(View(championsAdd)); } catch (Exception) { return(RedirectToAction("ErrorPage")); } }