Пример #1
0
        public async Task <BottleVM> UpdateBottle(Guid id, BottleVM bottle)
        {
            try
            {
                var updateBottle = await _ctx.Bottles.FindAsync(id);

                updateBottle.Color              = bottle.Color;
                updateBottle.YearVintage        = bottle.YearVintage;
                updateBottle.Winery             = bottle.Winery;
                updateBottle.Varietal           = bottle.Varietal;
                updateBottle.Vinyard            = bottle.Vinyard;
                updateBottle.Name               = bottle.Name;
                updateBottle.PurchaseDate       = bottle.PurchaseDate;
                updateBottle.PurchasePrice      = bottle.PurchasePrice;
                updateBottle.StorageDate        = bottle.StorageDate;
                updateBottle.StorageTemparature = bottle.StorageTemparature;
                updateBottle.OpenedDate         = bottle.OpenedDate;
                updateBottle.Notes              = bottle.Notes;

                await _ctx.SaveChangesAsync();

                return(bottle);
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        public async Task <IActionResult> Put(Guid id, [FromBody] BottleVM bottle)
        {
            try
            {
                var updateBottle = await _bottleService.UpdateBottle(id, bottle);

                return(Ok(updateBottle));
            }
            catch
            {
                return(StatusCode(500, "Interal server error"));
            }
        }
Пример #3
0
        public async Task <BottleVM> DrinkBottle(Guid id)
        {
            try
            {
                var updateBottle = await _ctx.Bottles.FindAsync(id);

                updateBottle.OpenedDate = DateTime.UtcNow;

                await _ctx.SaveChangesAsync();

                var bottleVM = new BottleVM()
                {
                    Id                 = updateBottle.Id,
                    Color              = updateBottle.Color,
                    YearVintage        = updateBottle.YearVintage,
                    Winery             = updateBottle.Winery,
                    Varietal           = updateBottle.Varietal,
                    Vinyard            = updateBottle.Vinyard,
                    Name               = updateBottle.Name,
                    PurchaseDate       = updateBottle.PurchaseDate,
                    PurchasePrice      = updateBottle.PurchasePrice,
                    StorageDate        = updateBottle.StorageDate,
                    StorageTemparature = updateBottle.StorageTemparature,
                    CreatedById        = updateBottle.CreatedById,
                    CreatedDateTime    = updateBottle.CreatedDateTime,
                    OpenedDate         = updateBottle.OpenedDate,
                    Notes              = updateBottle.Notes
                };

                return(bottleVM);
            }
            catch
            {
                throw;
            }
        }
Пример #4
0
        public async Task <Bottle> AddBottle(Guid bottleTypeId, BottleVM bottle)
        {
            try
            {
                var bottleType = await _ctx.BottleTypes.FindAsync(bottleTypeId);

                if (bottleType == null)
                {
                    var newBottleType = new CreateBottleTypeVM()
                    {
                        Color              = bottle.Color,
                        YearVintage        = bottle.YearVintage,
                        Winery             = bottle.Winery,
                        Varietal           = bottle.Varietal,
                        Vinyard            = bottle.Vinyard,
                        Name               = bottle.Name,
                        PurchaseDate       = bottle.PurchaseDate,
                        PurchasePrice      = bottle.PurchasePrice,
                        StorageDate        = bottle.StorageDate,
                        StorageTemparature = bottle.StorageTemparature,
                        CreatedById        = bottle.CreatedById,
                        CreatedDateTime    = bottle.CreatedDateTime,
                        OpenedDate         = bottle.OpenedDate,
                        Notes              = bottle.Notes,
                        NewBottleCount     = 1
                    };

                    var createdBottleType = await AddBottleType(newBottleType);

                    return(createdBottleType.Bottles.FirstOrDefault());
                }
                else
                {
                    var newBottle = new Bottle()
                    {
                        BottleTypeId       = bottleTypeId,
                        Color              = bottle.Color,
                        YearVintage        = bottle.YearVintage,
                        Winery             = bottle.Winery,
                        Varietal           = bottle.Varietal,
                        Vinyard            = bottle.Vinyard,
                        Name               = bottle.Name,
                        PurchaseDate       = bottle.PurchaseDate,
                        PurchasePrice      = bottle.PurchasePrice,
                        StorageDate        = bottle.StorageDate,
                        StorageTemparature = bottle.StorageTemparature,
                        CreatedById        = bottle.CreatedById,
                        CreatedDateTime    = bottle.CreatedDateTime,
                        OpenedDate         = bottle.OpenedDate,
                        Notes              = bottle.Notes
                    };

                    _ctx.Bottles.Add(newBottle);

                    await _ctx.SaveChangesAsync();

                    return(newBottle);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }