예제 #1
0
        /// <summary>
        /// Créer une ListOfIngredient
        /// </summary>
        /// <param name="listOfIngredient"></param>
        /// <returns></returns>
        public async Task <ListOfIngredient> CreateListOfIngredient(ListOfIngredient listOfIngredient)
        {
            _db.BeginTransaction();
            IListOfIngredientRepository _listOfIngredient   = _db.GetRepository <IListOfIngredientRepository>();
            ListOfIngredient            newListOfIngredient = await _listOfIngredient.InsertAsync(listOfIngredient);

            _db.Commit();
            return(newListOfIngredient);
        }
예제 #2
0
 public async Task <IActionResult> CreateListOfIngredient([FromBody] ListOfIngredient ListOfIngredient)
 {
     // Bug FIX : Important sur insert !
     if (ListOfIngredient != null)
     {
         //Créer une redirection vers GetIngredientById(NewIngredient.IngredientId)
         return(Ok(await _restaurantService.CreateListOfIngredient(ListOfIngredient)));
         //C'est fait.
     }
     else
     {
         //Retourner code 400 Bad Request
         return(BadRequest());
     }
 }
        /// <summary>
        /// Créer une table d'association entre un Ingrédient et un plat
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <ListOfIngredient> InsertAsync(ListOfIngredient entity)
        {
            var stmt = @"insert into listOfIngredients (IdIngredient, IdDish, Quantity)
            values (@IdIngredient, @IdDish, @Quantity)";

            try
            {
                await _session.Connection.ExecuteAsync(stmt, entity, _session.Transaction);

                return(entity);
            }
            catch (Exception)
            {
                throw new Exception("Error on the Insert ListOfIngredient request" + System.Reflection.MethodInfo.GetCurrentMethod().ToString());
            }
        }
예제 #4
0
        /// <summary>
        /// Créer un élément de liaison entre un plat et un ingrédient
        /// </summary>
        /// <param name="listOfIngredient"></param>
        /// <returns></returns>
        public async Task <ListOfIngredient> CreateListOfIngredient(ListOfIngredient listOfIngredient)
        {
            var response = await _httpClient.PostAsync("listOfIngredient",
                                                       new StringContent(
                                                           JsonSerializer.Serialize(listOfIngredient), Encoding.UTF8, "application/json"));

            if (response.IsSuccessStatusCode)
            {
                var stream = await response.Content.ReadAsStreamAsync();

                ListOfIngredient newListOfIngredient = await JsonSerializer.DeserializeAsync <ListOfIngredient>(stream, new JsonSerializerOptions()
                {
                    PropertyNameCaseInsensitive = true
                });

                return(newListOfIngredient);
            }
            else
            {
                return(null);
            };
        }
예제 #5
0
        public async Task <IActionResult> ModifyListOfIngredient([FromRoute] int id, [FromBody] ListOfIngredient listOfIngredient)
        {
            // Penser que id = int32.Parse(idIngredient.toString() + idDish.toString())
            if (listOfIngredient == null || id != Int32.Parse(listOfIngredient.IdIngredient.ToString() + listOfIngredient.IdDish.ToString()))
            {
                // Retourne un code 400  Bad Request
                return(BadRequest());
            }
            else
            {
                ListOfIngredient listOfIngredientModified = await _restaurantService.ModifyListOfIngredient(listOfIngredient);

                if (listOfIngredientModified != null)
                {
                    // Renvoie la ressource modifiée
                    return(Ok(listOfIngredientModified));
                }
                else
                {
                    // Renvoie un code 404: la ressource est introuvable
                    return(NotFound());
                }
            }
        }
예제 #6
0
 public Task <ListOfIngredient> ModifyListOfIngredient(ListOfIngredient listOfIngredient)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Non implémenté V.1
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public Task UpdateAsync(ListOfIngredient entity)
 {
     throw new NotImplementedException();
 }