public void AllowModifyEntityTest() { var claims = new List <Claim>() { new Claim(ClaimTypes.Name, "username"), new Claim(ClaimTypes.NameIdentifier, "123"), }; var result = _authorizationService.AllowModifyEntity(claims, "123"); Assert.True(result); }
public void Update(TripUpdate model, IEnumerable <Claim> claims) { var entity = _dbContext.Trips.SingleOrDefault(m => m.Id == model.Id); if (entity == null) { throw new NotFoundException(nameof(Trip), model.Id); } if (!_authorizationService.AllowModifyEntity(claims, entity.UserId)) { throw new NotAuthorizedException(); } entity.Price = model.Price; entity.Country = model.Country; entity.DateEnd = model.DateEnd; entity.DateStart = model.DateStart; _dbContext.Trips.Update(entity); _dbContext.SaveChanges(); }
public void Update(ArtistUpdate model, IEnumerable <Claim> claims) { var entity = _dbContext.Artists.SingleOrDefault(m => m.Id == model.Id); if (entity == null) { throw new NotFoundException(nameof(Artist), model.Id); } if (!_authorizationService.AllowModifyEntity(claims, entity.UserId)) { throw new NotAuthorizedException(); } entity.Birthday = model.Birthday; entity.Country = model.Country; entity.FirstName = model.FirstName; entity.LastName = model.LastName; _dbContext.Artists.Update(entity); _dbContext.SaveChanges(); }