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; } }
public Task <ResourceCreationResult <ReplaceKeg, int> > CreateAsync(ReplaceKeg resource, IRequestContext context, CancellationToken cancellation) { try { if (resource.Volume == 0) { resource.Volume = _initialBeerVolume; } context.SetLinkParameter <ReplaceKeg>(); var officeId = context.LinkParameters.Get <LinksParametersSource>().Value.OfficeId; var beerTapId = context.LinkParameters.Get <LinksParametersSource>().Value.BeerTapId; var result = _repository.Save(resource.ToBeerTapDto(officeId, beerTapId)); return(Task.FromResult(new ResourceCreationResult <ReplaceKeg, int>(new ReplaceKeg { Id = result.Id, BeerName = result.BeerName, Volume = result.Volume }))); } catch (Exception) { throw; } }