Exemple #1
0
        public async Task <CommonMealChef> UpdateChef(CommonMealChef chef)
        {
            var status = await _mealRepository.GetStatus(chef.CommonMealId);

            if (status != "OPEN")
            {
                throw new Exception($"The meal with id '{chef.CommonMealId}' is not open for chef changes");
            }

            chef.Timestamp = _timeProvider.Now();
            return(await _chefRepository.Update(chef));
        }
        public async Task <CommonMealChef> Update(CommonMealChef commonMealChef)
        {
            const string query =
                " UPDATE CommonMealChef " +
                " SET PersonId = @PersonId, date = @Date " +
                " WHERE Id = @Id ";

            using (var connection = _connectionFactory.New())
            {
                await connection.QueryAsync(query, new
                {
                    Id       = commonMealChef.Id,
                    PersonId = commonMealChef.PersonId,
                    Date     = commonMealChef.Timestamp
                });

                return(commonMealChef);
            }
        }
        public async Task <CommonMealChef> Add(CommonMealChef commonMealChef)
        {
            const string query =
                " INSERT INTO CommonMealChef (personId, date, commonMealId) " +
                " VALUES (@PersonId, @Date, @CommonMealId) " +
                " RETURNING id ";

            using (var connection = _connectionFactory.New())
            {
                var id = await connection.QueryAsync <int>(query, new
                {
                    PersonId     = commonMealChef.PersonId,
                    Date         = commonMealChef.Timestamp,
                    CommonMealId = commonMealChef.CommonMealId
                });

                commonMealChef.Id = id.Single();
                return(commonMealChef);
            }
        }