public async Task Update(QuizeViewModel item) { string relativeUri = $"QuizesDefinition/{item.Id}"; var bodyJson = new StringContent(JsonSerializer.Serialize(item), Encoding.UTF8, "application/json"); await _httpClient.PutAsync(relativeUri, bodyJson); }
protected override async Task OnInitializedAsync() { int.TryParse(QuizeId, out var quizeId); if (quizeId == 0) //new Quize is being created { //add some defaults Quize = new QuizeViewModel { Id = 0 }; } else { Quize = await QuizeService.GetById(quizeId); } }
public async Task <QuizeViewModel> Create(QuizeViewModel item) { string relativeUri = $"QuizesDefinition"; var bodyJson = new StringContent(JsonSerializer.Serialize(item), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync(relativeUri, bodyJson); if (response.IsSuccessStatusCode) { return(await JsonSerializer.DeserializeAsync <QuizeViewModel>( await response.Content.ReadAsStreamAsync(), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true })); } return(null); }
protected async Task HandleValidSubmit() { Saved = false; if (Quize.Id == 0) //new { var addedQuize = await QuizeService.Create(Quize); if (addedQuize != null) { //StatusClass = "alert-success"; //Message = "New Quize added successfully."; Saved = true; if (addedQuize?.Id > 0) { Quize = addedQuize; NavigateToOverview(); } } else { StatusClass = "alert-danger"; Message = "Something went wrong adding the new Quize. Please try again."; Saved = false; } } else { await QuizeService.Update(Quize); //StatusClass = "alert-success"; //Message = "Quize updated successfully."; Saved = true; NavigateToOverview(); } }
protected override async Task OnInitializedAsync() { Quize = await QuizeService.GetById(QuizeId); }
public async Task <QuizeViewModel> Create(QuizeViewModel item) { return(_mapper.Map <QuizeViewModel>(await Create(_mapper.Map <Quize>(item)))); }