private async void OnSave(object obj) { if (IsBusy) { return; } IsBusy = true; try { // Thuc hien cong viec tai day var param = new NavigationParameters(); if (QuantityBindProp > 0) { var history = new ImportExportHistoryDto { Quantity = QuantityBindProp, ItemId = ItemBindProp.Id, ItemName = ItemBindProp.Name, Reason = IsSelectingOtherReason == true ? OtherReasonBindProp : _reason }; var json = JsonConvert.SerializeObject(history); var content = new StringContent(json, Encoding.UTF8, "application/json"); using (var client = new HttpClient()) { var response = await client.PostAsync(Properties.Resources.BaseUrl + "histories/", content); if (response.IsSuccessStatusCode) { var newHistory = JsonConvert.DeserializeObject <ImportExportHistoryDto>(await response.Content.ReadAsStringAsync()); ItemBindProp.CurrentQuantity += newHistory.Quantity; param.Add("History", newHistory); await NavigationService.GoBackAsync(param); } else { await PageDialogService.DisplayAlertAsync("Lỗi hệ thống", await response.Content.ReadAsStringAsync(), "Đóng"); } } } else { await PageDialogService.DisplayAlertAsync("Cảnh báo", "Bạn chưa nhập số lượng giảm!", "OK"); } } catch (Exception e) { await ShowErrorAsync(e); } finally { IsBusy = false; } }
public async Task <IActionResult> CreateHistory(ImportExportHistoryDto historyDto) { var history = await _mediator.Send(new AddHistoryCommand(historyDto)); if (history != null) { return(Ok(history)); } else { return(BadRequest("Không thể tạo mới!")); } }