Пример #1
0
        //Gets a drink-object based on its id.
        public async Task <DrinkForListDto> GetDrink(int id)
        {
            var dbDrink = await _context.Drinks
                          .FirstOrDefaultAsync(e => e.Id == id);

            var dr = DrinkTranslator.TodrinkForListDto(dbDrink);

            return(dr);
        }
Пример #2
0
        //Image upload.
        public async Task <DrinkForListDto> UploadDrinkImage(int id, IFormFile image)
        {
            var dbDrink = await _context.Drinks.FindAsync(id);

            var uploadResult = await _cloudinaryService.UploadImage(image, "drink-images", dbDrink.ImageId);

            dbDrink.Image   = uploadResult.Uri.ToString();
            dbDrink.ImageId = uploadResult.PublicId;

            await _context.SaveChangesAsync();

            return(DrinkTranslator.TodrinkForListDto(dbDrink));
        }
Пример #3
0
        //Creates a drink object with the listed paramteters below.
        public async Task <DrinkForListDto> Create(DrinkForListDto drink)
        {
            var dr = new Drink()
            {
                ProductNameBold = drink.ProductNameBold,
                Category        = drink.Category,
                Volume          = drink.Volume,
                Price           = drink.Price,
                Taste           = drink.Taste,
                Image           = drink.Image
            };

            _context.Drinks.Add(dr);
            await _context.SaveChangesAsync();

            return(DrinkTranslator.TodrinkForListDto(dr));
        }