예제 #1
0
        public async Task <bool> UpdateGarage(GarageEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = await ctx.Garages.SingleAsync(g => g.Id == model.Id && g.CollectorId == _userId);

                entity.Location = model.Location;
                entity.Name     = model.Name;

                return(await ctx.SaveChangesAsync() == 1);
            }
        }
        public async Task <IHttpActionResult> Put(GarageEdit garage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateGarageService();

            if (!(await service.UpdateGarage(garage)))
            {
                return(InternalServerError());
            }

            return(Ok());
        }