コード例 #1
0
        public long Create(MealBooking meal)
        {
            var id = MealBookings.Count;

            meal.Id = id;
            MealBookings.Add(meal);
            return(id);
        }
コード例 #2
0
        public IActionResult Update([FromBody] MealBooking mealBooking)
        {
            var result = new UpdateMealBooking(Repository, mealBooking).Execute();

            if (result == -1)
            {
                return(Conflict());
            }
            return(Ok(result));
        }
コード例 #3
0
        public long Create(MealBooking meal)
        {
            const string sql =
                "INSERT INTO public.\"MealReservation\"(\"Id\", \"MealId\", \"UserId\", \"Note\")VALUES (DEFAULT, @mealId, @userId, @note) RETURNING \"MealReservation\".\"Id\";";
            var par = new List <DbParameter> {
                new NpgsqlParameter("mealId", meal.MealId),
                new NpgsqlParameter("userId", meal.UserId),
                new NpgsqlParameter("note", meal.Note)
            };

            return(datamapper.NoQueryCommand(sql, par));
        }
コード例 #4
0
        public long Update(MealBooking meal)
        {
            const string sql =
                "UPDATE public.\"MealReservation\" SET \"MealId\"= @mealId, \"UserId\"= @userId, \"Note\"= @note WHERE \"Id\"= @id RETURNING \"MealReservation\".\"Id\";";
            var par = new List <DbParameter> {
                new NpgsqlParameter("id", meal.Id),
                new NpgsqlParameter("mealId", meal.MealId),
                new NpgsqlParameter("userId", meal.UserId),
                new NpgsqlParameter("note", meal.Note)
            };

            return(datamapper.NoQueryCommand(sql, par));
        }
コード例 #5
0
        public long Update(MealBooking item)
        {
            long id = -1;

            MealBookings = MealBookings.Select(i => {
                if (i.Id == item.Id)
                {
                    id = item.Id;
                    return(item);
                }
                id = -1;
                return(i);
            }).ToList();
            return(id);
        }
コード例 #6
0
        protected override DinnerBooking DoPostPutDto(Client currentClient, DinnerBookingDTO dto, DinnerBooking entity, string path, object param)
        {
            if (entity == null)
            {
                entity = new DinnerBooking();
            }
            else
            {
                if (dto.PriceHT == null)
                {
                    dto.PriceHT = entity.PriceHT;
                }
                if (dto.PriceTTC == null)
                {
                    dto.PriceTTC = entity.PriceTTC;
                }
            }
            GetMapper.Map(dto, entity);
            if (dto.Booking != null && dto.Booking.Id != 0)
            {
                entity.Booking = BookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Booking, currentClient, path);
            }
            if (dto.MealBookings != null)
            {
                MealRepository.DeleteRange(entity.MealBookings.Where(d => !dto.MealBookings.Any(x => x.Id == d.Id)));
                dto.MealBookings.ForEach(mealBooking =>
                {
                    if (entity.MealBookings.Count != 0 && mealBooking.Id != 0 &&
                        entity.MealBookings.Find(p => p.Id == mealBooking.Id) != null)
                    {
                        return;
                    }
                    MealBooking toAdd = MealBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, mealBooking, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.MealBookings.Add(toAdd);
                    }
                });
            }
            return(entity);
        }