コード例 #1
0
        public async Task <ActionResult <HairSize> > PostHairSize(HairSize hairSize)
        {
            _context.HairSizes.Add(hairSize);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetHairSize", new { id = hairSize.HairSizeId }, hairSize));
        }
コード例 #2
0
        public async Task <IActionResult> PutHairSize(short id, HairSize hairSize)
        {
            if (id != hairSize.HairSizeId)
            {
                return(BadRequest());
            }

            _context.Entry(hairSize).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HairSizeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> Edit(short id, [Bind("HairSizeId,HairSizeName")] HairSize hairSize)
        {
            try
            {
                if (id != hairSize.HairSizeId)
                {
                    return(NotFound());
                }

                // Préparation de l'appel à l'API
                string accessToken = await HttpContext.GetTokenAsync("access_token");

                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                if (ModelState.IsValid)
                {
                    // Préparation de la requête update à l'API
                    StringContent       httpContent = new StringContent(hairSize.ToJson(), Encoding.UTF8, "application/json");
                    HttpResponseMessage response    = await client.PutAsync(_configuration["URLAPI"] + $"api/HairSizes/{id}", httpContent);

                    if (response.StatusCode != HttpStatusCode.NoContent)
                    {
                        return(BadRequest());
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(hairSize));
            }
            catch (HttpRequestException)
            {
                return(Unauthorized());
            }
        }
コード例 #4
0
        // GET: HairSizes/Details/5
        public async Task <IActionResult> Details(short?id)
        {
            try
            {
                if (id == null)
                {
                    return(NotFound());
                }

                // Préparation de l'appel à l'API
                string accessToken = await HttpContext.GetTokenAsync("access_token");

                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Récurération des données et convertion des données dans le bon type
                string content = await client.GetStringAsync(_configuration["URLAPI"] + $"api/HairSizes/{id}");

                HairSize hairSize = JsonConvert.DeserializeObject <HairSize>(content);

                if (hairSize == null)
                {
                    return(NotFound());
                }

                return(View(hairSize));
            }
            catch (HttpRequestException)
            {
                return(Unauthorized());
            }
        }
コード例 #5
0
ファイル: Dog.cs プロジェクト: Firelexic/Learned
 public Dog(HairSize sizeHair)
 {
     this.sizeHair = sizeHair;
 }