コード例 #1
0
        public Task <ResourceCreationResult <PourBeer, int> > CreateAsync(PourBeer resource, IRequestContext context, CancellationToken cancellation)
        {
            try
            {
                context.SetLinkParameter <PourBeer>();
                var beerTapId = context.LinkParameters.Get <LinksParametersSource>().Value.BeerTapId;
                var beerTap   = _repository.Get(beerTapId);

                if (resource.Volume > beerTap.Volume)
                {
                    resource.Volume = beerTap.Volume;
                }

                beerTap.Volume = beerTap.Volume - resource.Volume;
                var newStatus = (BeerTapStatus)GetNewStatus(beerTap);

                beerTap.Status = (int)newStatus;
                _repository.Save(beerTap);

                return(Task.FromResult(new ResourceCreationResult <PourBeer, int>(new PourBeer
                {
                    Id = beerTapId,
                    Volume = beerTap.Volume
                })));
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
 public Task <BeerTap> GetAsync(int id, IRequestContext context, CancellationToken cancellation)
 {
     try
     {
         if (context == null)
         {
             throw new ArgumentNullException(nameof(context));
         }
         context.SetLinkParameter <BeerTap>(id);
         return(Task.FromResult(_repository.Get(id).ToBeerTapResource()));
     }
     catch (Exception)
     {
         throw;
     }
 }