public async Task SaveRoast(RoastsSaveRoastAction action, IDispatcher dispatcher) { foreach (var gb in action.Roast.Beans) { if (gb.Id == 0) { var result = await _httpClient.PostAsJsonAsync <CoffeeRoastManagement.Shared.Entities.GreenBlend>("api/greenblend", gb); gb.Id = int.Parse(await result.Content.ReadAsStringAsync()); } else { var result = await _httpClient.PutAsJsonAsync("api/greenblend", gb); } } if (action.Roast.Id == 0) { var result = await _httpClient.PostAsJsonAsync("api/roast", action.Roast); if (!result.IsSuccessStatusCode) { dispatcher.Dispatch(new RoastCreateFailureAction(result.ReasonPhrase)); } else { dispatcher.Dispatch(new RoastCreateSuccessAction()); } } else { var result = await _httpClient.PutAsJsonAsync("api/roast", action.Roast); if (!result.IsSuccessStatusCode) { dispatcher.Dispatch(new RoastUpdateFailureAction(result.ReasonPhrase)); } else { dispatcher.Dispatch(new RoastUpdateSuccessAction()); } } dispatcher.Dispatch(new RoastsLoadAction()); }
public static RoastsState OnSaveRoast(RoastsState state, RoastsSaveRoastAction action) { return(state with { Submitted = false, Submitting = true, CurrentRoast = new CoffeeRoastManagement.Shared.Entities.Roast(), RoastButtonText = "Create", ShowInputDialog = false, RoastEditMode = false, Name = string.Empty, ShortInfo = string.Empty, Note = string.Empty, GreenBlends = Array.Empty <CoffeeRoastManagement.Shared.Entities.GreenBlend>(), Date = null, Time = null, Equipment = string.Empty, ErrorMessage = string.Empty, Photo = string.Empty, RoastProfile = string.Empty, }); }