Exemplo n.º 1
0
        public async Task <BoughtIngredient> Save(BoughtIngredient item, int groupId)
        {
            using (var connection = new SqlConnection(this.connectionString))
            {
                var query = @"
                              update BoughtIngredients set Bought = @date where weekplanid=@weekplan and Day=@day and ingredient=@ingredient;
                              IF @@ROWCOUNT=0
                              Begin
                                insert into BoughtIngredients(Bought, WeekPlanId, Day, Ingredient, GroupId) values(@date, @weekplan, @day, @ingredient, @groupId);
                              
                                select @@identity
                              end";

                var id = await connection.QueryFirstOrDefaultAsync <int>(query, new { date       = item.Bought,
                                                                                      weekplan   = item.WeekPlanId,
                                                                                      day        = item.Day,
                                                                                      ingredient = item.Ingredient.Id,
                                                                                      groupId });

                item.Id = id > 0 ? id : item.Id;
                return(item);
            }
        }
        public async Task <ActionResult> Save([FromBody] BoughtIngredient item)
        {
            var existingItem = await this.boughtIngredientRepository.Save(item, this.GroupId().Value);

            return(Ok());
        }