public async Task <ActionResult <CoursePathModel> > PostAsync([Required] CoursePathModel model) { // to keep the compiler happy if (model is null) { return(BadRequest()); } // attempt to set the entry CoursePath result; try { result = await _factory .GetCoursePathGrain(model.Key) .SetAsync(_mapper.Map <CoursePath>(model)) .ConfigureAwait(false); } catch (ConcurrencyException ex) { // handle version conflict return(Conflict(new ConflictApiResponseModel { VersionConflict = new VersionConflictApiResponseModel { StoredVersion = ex.StoredVersion, CurrentVersion = ex.CurrentVersion } })); } catch (NameAlreadyExistsException ex) { // handle name conflict return(Conflict(new ConflictApiResponseModel { NameConflict = new NameConflictApiResponseModel { Key = model.Key, Name = ex.Name } })); } catch (SlugAlreadyExistsException ex) { // handle slug conflic return(Conflict(new ConflictApiResponseModel { SlugConflict = new SlugConflictApiResponseModel { Key = model.Key, Slug = ex.Slug } })); } return(Ok(_mapper.Map <CoursePathModel>(result))); }
protected override async Task OnInitializedAsync() { if (Key.HasValue) { var result = await Client.GetCoursePathAsync(Key.Value).ConfigureAwait(true); if (result is null) { IsValid = false; } else { Model = Mapper.Map <CoursePathModel>(result); } } else { Model = new CoursePathModel { Key = Guid.NewGuid() }; } }