public async Task UpdateAsync(ClaimTypeViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!model.Id.HasValue) { throw new ArgumentNullException(nameof(model.Id)); } var claimType = await this.context.ClaimTypes.FindAsync(model.Id.Value); if (claimType == null) { throw new ArgumentNullException(nameof(claimType)); } claimType.Name = model.Name; claimType.Description = model.Description; this.context.ClaimTypes.Update(claimType); await this.context.SaveChangesAsync(); }
public async Task <IActionResult> UpdateAsync([FromBody] ClaimTypeViewModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await this.service.UpdateAsync(model); return(NoContent()); }
public async Task <IActionResult> CreateAsync([FromBody] ClaimTypeViewModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await this.service.CreateAsync(model); return(Created($"api/claimtypes/{result}", this.Json(result))); }
public async Task <Guid> CreateAsync(ClaimTypeViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } // TODO: Check whether name already exists var claimType = ClaimType.Create(model.Name, model.Description); this.context.ClaimTypes.Add(claimType); await this.context.SaveChangesAsync(); return(claimType.Id); }