public IHttpActionResult Delete(UserClaimModel userClaimModel) { var user = _context.Users.FirstOrDefault(c => c.Id == userClaimModel.UserId); if (user == null) { return NotFound(); } userClaimModel.Claims.RemoveAll(c => userClaimModel.Claims.Contains(c)); _context.SaveChanges(); return Ok(); }
public IHttpActionResult Post(UserClaimModel userClaimModel) { if (!ModelState.IsValid) return BadRequest(ModelState); var user = _context.Users.FirstOrDefault(c => c.Id == userClaimModel.UserId); if (user == null) { return NotFound(); } userClaimModel.Claims.ForEach(c=>user.Claims.Add(new UserClaim(){ClaimType = c.Type,ClaimValue = c.Value})); var errors = _context.GetValidationErrors().ToList(); if (!errors.Any()) { _context.SaveChanges(); return Created(Request.RequestUri + userClaimModel.UserId.ToString(), userClaimModel.Claims); } var sb = new StringBuilder(); errors.SelectMany(c=>c.ValidationErrors).ToList().ForEach(c=>sb.Append(c.ErrorMessage)); return BadRequest(sb.ToString()); }