public async Task <IActionResult> OnPostAsync() { await InitData(); if (!ModelState.IsValid) { return(Page()); } _order.poNumber = poNum; _order.orderDate = orderDate; _device.poNumber = poNum; await poRepository.Create(_order); await deviceRepository.Create(_device); return(Redirect("View/" + poNumSt)); }
private void SaveBtn_Click(object sender, EventArgs e) { try { string id = "0"; if (!IdTxt.Text.Equals("")) { id = IdTxt.Text.ToString(); } string idRequest = "0"; if (!RequestCbx.SelectedIndex.ToString().Equals("")) { idRequest = RequestCbx.SelectedIndex.ToString(); } purchase.Id = int.Parse(id); purchase.ItemRequest = int.Parse(idRequest); purchase.Date = DatePckr.Value; purchase.Status = StatusCbx.SelectedIndex.ToString(); purchase.Item = ItemCbx.SelectedIndex.ToString(); int.TryParse(QuantityTxt.Text, out int quantity); purchase.Quantity = quantity; purchase.Unit = UnitCbx.SelectedIndex.ToString(); purchase.Brand = BrandCbx.SelectedIndex.ToString(); double.TryParse(PriceTxt.Text, out double price); purchase.Price = price; PurchaseOrder data = new PurchaseOrder { Id = purchase.Id, ItemRequestId = _Context.ItemRequests .Where(x => x.Id == (RequestCbx.SelectedIndex + 1)) .Select(x => x.Id) .FirstOrDefault(), Date = purchase.Date, StatusId = _Context.Statuses .Where(x => x.Id == (StatusCbx.SelectedIndex + 1)) .Select(x => x.Id) .FirstOrDefault(), ItemId = _Context.Items .Where(x => x.Id == (ItemCbx.SelectedIndex + 1)) .Select(x => x.Id) .FirstOrDefault(), Quantity = purchase.Quantity, UnitId = _Context.Units .Where(x => x.Id == (UnitCbx.SelectedIndex + 1)) .Select(x => x.Id) .FirstOrDefault(), BrandId = _Context.Brands .Where(x => x.Id == (BrandCbx.SelectedIndex + 1)) .Select(x => x.Id) .FirstOrDefault(), Price = purchase.Price }; if (mode.Equals("Create")) { purchaseOrderRepo.Create(data); } else { purchaseOrderRepo.Update(data); } Close(); MessageBox.Show( text: "Registro guardado con exito", caption: "Informacion", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Information); } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show( text: "Error al guardar los datos", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } }