Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 3
0
        //Updates a drink-object with same parameters but different values.
        public async Task <DrinkForUpdateDto> Update(int id, DrinkForUpdateDto dr)
        {
            var dbDrink = await _context.Drinks
                          .FirstOrDefaultAsync(e => e.Id == id);

            dbDrink.ProductNameBold = dr.ProductNameBold;
            dbDrink.Price           = dr.Price;
            dbDrink.Volume          = dr.Volume;
            dbDrink.Category        = dr.Category;
            dbDrink.Taste           = dr.Taste;
            dbDrink.Image           = dr.Image;

            await _context.SaveChangesAsync();

            return(DrinkTranslator.ToDrinkForUpdateDto(dbDrink));
        }
Esempio n. 4
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));
        }