示例#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
     });
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }