public async Task <IActionResult> Update([FromBody] SubsetGroupPostModel subsetGroupForm, int subsetId) { var subsetGroup = await _subsetRepository.GetByName(subsetGroupForm.Name).ConfigureAwait(false); if (subsetGroup != null && subsetGroup.SubsetId != subsetId) { return(BadRequest($"Subset with Name '{subsetGroupForm.Name}' already exists")); } subsetGroup = await _subsetRepository.GetById(subsetId).ConfigureAwait(false); if (subsetGroup == null) { return(NotFound($"No Subset with Id '{subsetId}' exists")); } subsetGroup = await _subsetRepository.Update(new SubsetGroup { SubsetId = subsetId, Name = subsetGroupForm.Name, Items = subsetGroupForm.ItemIds.Select(i => new Item { ItemId = i }).ToList() }).ConfigureAwait(false); return(Ok(subsetGroup)); }
public async Task <IActionResult> Create([FromBody] SubsetGroupPostModel subsetGroupForm) { if (await _subsetRepository.GetByName(subsetGroupForm.Name).ConfigureAwait(false) != null) { return(BadRequest($"Subset with Name '{subsetGroupForm.Name}' already exists")); } var subsetGroup = await _subsetRepository.Create(new SubsetGroup { Name = subsetGroupForm.Name, Items = subsetGroupForm.ItemIds.Select(i => new Item { ItemId = i }).ToList() }).ConfigureAwait(false); var createdAtUri = HttpContext.Request.CreateCreatedUri($"api/subsets/{subsetGroup.SubsetId}"); return(Created(createdAtUri, subsetGroup)); }