Beispiel #1
0
        //private ActionResult<IEnumerable<WinePriceAdjustDto>> MapWinesToDto(IEnumerable<Wine> winesFromService)
        //{
        //    var wineDtos = _mapper.Map<IEnumerable<WineDto>>(winesFromService);

        //    //Add a "links" collection to each Wine object returned.
        //    foreach (var wineDto in wineDtos)
        //    {
        //        wineDto.Links = CreateLinksForWine(wineDto);
        //    }

        //    return Ok(wineDtos);
        //}

        private List <LinkDto> CreateLinksForWine(WineDto wineDto)
        {
            var links = new List <LinkDto>
            {
                // Add the "filter_by_id" link
                new LinkDto(Url.Link(nameof(GetWineAsync), new { id = wineDto.Id }), "filter_by_id", "GET")
            };

            return(links);
        }
Beispiel #2
0
        public static async Task Delete(WineDto wineToDelete)
        {
            await using MyWineCellarDbContext dbContext   = new MyWineCellarDbContext();
            await using IDbContextTransaction transaction = await dbContext.Database.BeginTransactionAsync();

            Wine wineDeleted = dbContext.Wines.Remove(Mapper.Map <Wine>(wineToDelete)).Entity;
            await dbContext.SaveChangesAsync();

            if (wineToDelete.Id.Equals(wineDeleted.Id))
            {
                await transaction.CommitAsync();
            }
        }
Beispiel #3
0
        public static async Task Add(WineDto wineToAdd)
        {
            await using MyWineCellarDbContext dbContext   = new MyWineCellarDbContext();
            await using IDbContextTransaction transaction = await dbContext.Database.BeginTransactionAsync();

            Wine wineAdded = (await dbContext.Wines.AddAsync(Mapper.Map <Wine>(wineToAdd))).Entity;
            await dbContext.SaveChangesAsync();

            if (wineAdded.Id > 0)
            {
                await transaction.CommitAsync();
            }
        }
Beispiel #4
0
 public IActionResult SynchronizeSingle([FromBody] WineDto wineDtos)
 {
     if (wineDtos != null)
     {
         dynamic res = _productService.PMSynchronize(new List <WineDto> {
             wineDtos
         });
         return(Json(res));
     }
     else
     {
         return(Json(new { state = "no data" }));
     }
 }