Exemple #1
0
 public static BeerTapDto ToBeerTapDto(this BeerTap resource)
 {
     return(new BeerTapDto
     {
         Id = resource.Id,
         BeerName = resource.BeerName,
         OfficeId = resource.OfficeId,
         Status = (int)resource.Status,
         Volume = resource.Volume
     });
 }
        public async Task <ResourceCreationResult <BeerTap, int> > CreateAsync(BeerTap resource, IRequestContext context,
                                                                               CancellationToken cancellation)
        {
            db.BeerTaps.Add(resource);
            await db.SaveChangesAsync(cancellation);

            db.Entry(resource).Reference(x => x.Office).Load();

            var result = new ResourceCreationResult <BeerTap, int>(resource);

            return(result);
        }
        public async Task <BeerTap> UpdateAsync(BeerTap resource, IRequestContext context, CancellationToken cancellation)
        {
            db.Entry(resource).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync(cancellation);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BeerTapExists(resource.Id))
                {
                    throw context.CreateNotFoundHttpResponseException <BeerTap>();
                }
                else
                {
                    throw;
                }
            }

            return(resource);
        }