public Task <ReplaceKeg> UpdateAsync(ReplaceKeg resource, IRequestContext context, CancellationToken cancellation) { var officeId = context.UriParameters.GetByName <int>("OfficeId").EnsureValue(() => context.CreateHttpResponseException <Office>("The placeId must be supplied in the URI", HttpStatusCode.BadRequest)); var kegId = context.UriParameters.GetByName <int>("Id").EnsureValue(() => context.CreateHttpResponseException <Keg>("The placeId must be supplied in the URI", HttpStatusCode.BadRequest)); _kegProvider.ReplaceKeg(officeId, kegId); return(Task.FromResult(resource)); }
public Task <ResourceCreationResult <ReplaceKeg, int> > CreateAsync(ReplaceKeg resource, IRequestContext context, CancellationToken cancellation) { var tapId = context.UriParameters.GetByName <int>("TapId").EnsureValue(() => context.CreateHttpResponseException <Tap>("The TapId must be supplied in the URI", HttpStatusCode.BadRequest)); Tap tap = _tapService.ReplaceKeg(tapId, resource.Keg); resource.Tap = tap; return(Task.FromResult(new ResourceCreationResult <ReplaceKeg, int>(resource))); }
public static BeerTapDto ToBeerTapDto(this ReplaceKeg resource, int officeId, int beerTapId) { return(new BeerTapDto { Id = beerTapId, BeerName = resource.BeerName, OfficeId = officeId, Status = (int)BeerTapStatus.New, Volume = resource.Volume }); }
public Task <ReplaceKeg> UpdateAsync(ReplaceKeg resource, IRequestContext context, CancellationToken cancellation) { var officeId = GetOfficeId(context); var id = context.UriParameters.GetByName <int>("Id").EnsureValue(); var newResource = _replacekeg.ReplaceKeg(id, officeId); resource = resource ?? new ReplaceKeg(); resource.Id = newResource.Id; resource.Amount = newResource.Container; resource.OfficeId = newResource.OfficeId; return(Task.FromResult(resource)); }
public Task <ReplaceKeg> UpdateAsync(ReplaceKeg resource, IRequestContext context, CancellationToken cancellation) { var officeId = context.UriParameters.GetByName <int>("OfficeID").EnsureValue(); var beerId = context.UriParameters.GetByName <int>("Id").EnsureValue(); resource.OfficeId = officeId; var linkParameter = new ReplaceKegLinkParameter(officeId, beerId); context.LinkParameters.Set(linkParameter); _iReplaceKegService.ReplaceKeg(officeId, beerId); return(Task.FromResult(resource)); }
public Task <ResourceCreationResult <ReplaceKeg, int> > CreateAsync(ReplaceKeg resource, IRequestContext context, CancellationToken cancellation) { int officeId = ServiceHelper.GetUrlParameters <Office>(context, "OfficeId"); int officeInfoId = ServiceHelper.GetUrlParameters <OfficeInfo>(context, "OfficeInfoId"); var oldKeg = _repository.Get(officeInfoId); oldKeg.Milliliter = oldKeg.Milliliter + resource.Milliliter; oldKeg.Beertype = resource.Beertype ?? oldKeg.Beertype; _repository.Update(oldKeg); _repository.SaveChanges(); context.LinkParameters.Set(new LinksParametersSource(officeId, officeInfoId)); return(Task.FromResult(new ResourceCreationResult <ReplaceKeg, int>(resource))); }
public Task <ReplaceKeg> UpdateAsync(ReplaceKeg resource, IRequestContext context, CancellationToken cancellation) { //_repository = new BeeerTapRepository(); //Keg k; //var tapId = context.UriParameters.GetByName<int>("Id").EnsureValue(() => context.CreateHttpResponseException<Tap>("The TapId must be supplied in the URI", HttpStatusCode.BadRequest)); //Tap t = _repository.GetTapById(tapId); ////check if Tap exist. //if (t != null) //{ // k = _repository.ReplaceKeg(resource.Keg); //} //else // throw new Exception("Tap doesn't exist. Cannot replace keg."); return(Task.FromResult(resource)); }
public Task <ResourceCreationResult <ReplaceKeg, int> > CreateAsync(ReplaceKeg resource, IRequestContext context, CancellationToken cancellation) { var officeId = context.UriParameters.GetByName <int>("OfficeId") .EnsureValue( () => context.CreateHttpResponseException <BeerTap>( "The officeId must be supplied in the URI", HttpStatusCode.BadRequest)); var beerTapId = context.UriParameters.GetByName <int>("BeerTapId") .EnsureValue( () => context.CreateHttpResponseException <BeerTap>( "The BeerTapId must be supplied in the URI", HttpStatusCode.BadRequest)); var beerTap = db.BeerTaps.Include(b => b.Office).SingleOrDefault(b => b.Id == beerTapId); if (beerTap == null) { throw context.CreateNotFoundHttpResponseException <BeerTap>(); } beerTap.Volume = resource.ML; if (beerTap.Volume == 0) { beerTap.BeerTapState = BeerTapState.Dry; } else if (beerTap.Volume < 50) { beerTap.BeerTapState = BeerTapState.AlmostGone; } else if (beerTap.Volume < 100) { beerTap.BeerTapState = BeerTapState.NotSoNew; } else { beerTap.BeerTapState = BeerTapState.New; } db.Entry(beerTap).State = EntityState.Modified; try { db.SaveChangesAsync(cancellation); } catch (DbUpdateConcurrencyException) { if (!BeerTapExists(beerTap.Id)) { throw context.CreateNotFoundHttpResponseException <BeerTap>(); } else { throw; } } return(Task.FromResult(new ResourceCreationResult <ReplaceKeg, int>(resource))); }
public Task <ReplaceKeg> UpdateAsync(ReplaceKeg resource, IRequestContext context, CancellationToken cancellation) { throw new NotImplementedException(); }