public async Task <IActionResult> ClientEditor(int id, ClientViewModel model) { if (ModelState.IsValid) { var oldClient = await _context.Clients .Include(c => c.Address) .Where(c => c.Id == id) .FirstOrDefaultAsync(); if (oldClient != null) { _mapper.Map(model, oldClient); if (await _context.SaveChangesAsync() > 0) { return(RedirectToAction("Index")); } } else { var newClient = _mapper.Map <Client>(model); _context.Add(newClient); if (await _context.SaveChangesAsync() > 0) { return(RedirectToAction("Index")); } } } return(View()); }
public async Task <ActionResult <TimeBillViewModel> > Post([FromBody] TimeBillViewModel model) { var bill = _mapper.Map <TimeBill>(model); var theCase = await _ctx.Cases .Where(c => c.Id == model.CaseId) .FirstOrDefaultAsync(); var theEmployee = await _ctx.Employees .Where(e => e.Id == model.EmployeeId) .FirstOrDefaultAsync(); if (theCase == null || theEmployee == null) { return(BadRequest("Could not find case or employee")); } bill.Case = theCase; bill.Employee = theEmployee; _ctx.Add(bill); if (await _ctx.SaveChangesAsync() > 0) { return(CreatedAtAction("Get", new { id = bill.Id }, _mapper.Map <TimeBillViewModel>(bill))); } return(BadRequest("Failed to save new timebill")); }
private async void btnCrear_Click(object sender, EventArgs e) { using (var fromAgregar = new AgregarFactura(new Factura())) { if (fromAgregar.ShowDialog() == DialogResult.OK) { try { fromAgregar.FacturaCurrent.Fecha = DateTime.Now; // facturasBindingSource.Add(fromAgregar.FacturaCurrent); var facturaGuardada = db.Factura.Add(fromAgregar.FacturaCurrent); if (fromAgregar.CondicionesPago != null && fromAgregar.CondicionesPago.CantidadDias > 0) { fromAgregar.CondicionesPago.IdEstadoPago = 1; fromAgregar.CondicionesPago.IdFactura = facturaGuardada.Id; db.CondicionesPago.Add(fromAgregar.CondicionesPago); } // facturasBindingSource.EndEdit(); await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } updateFacturaGrid(); }
private async void metroTile2_Click(object sender, EventArgs e) { using (var fromAgregar = new frmAgregarClientes(new Cliente())) { if (fromAgregar.ShowDialog() == DialogResult.OK) { try { clienteBindingSource.Add(fromAgregar.ClienteCurrent); db.Clientes.Add(fromAgregar.ClienteCurrent); clienteBindingSource.EndEdit(); await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public async Task <ActionResult <TimeBill> > Post([FromBody] TimeBill bill) { var theCase = await _ctx.Cases .Where(c => c.Id == bill.Case.Id) .FirstOrDefaultAsync(); var theEmployee = await _ctx.Employees .Where(e => e.Id == bill.Employee.Id) .FirstOrDefaultAsync(); bill.Case = theCase; bill.Employee = theEmployee; _ctx.Add(bill); if (await _ctx.SaveChangesAsync() > 0) { return(CreatedAtAction("Get", new { id = bill.Id }, bill)); } return(BadRequest("Failed to save new timebill")); }
public string CreateOrder(OrderViewModel model) { try { var address = new AddressMaster(); address.CompleteAddress = model.Address; address.ZipCode = model.ZipCode; var order = new OrderMaster(); order.AddressId = address.AddressId; order.Address = address; order.CreatedOn = DateTime.UtcNow; order.CustomerName = model.CustomerName; order.IsPaid = true; order.OrderNumber = 0; order.PaymentType = model.PaymentType; order.Quantity = model.Quantity; order.Remarks = model.Remarks; order.TotalAmount = model.TotalAmount; order.NumberOfScoop = model.Quantity; var orderList = new List <OrderDetail>(); if (model.IceCreamId != 0) { var orderDetails = new OrderDetail(); orderDetails.OrderNumber = order.OrderNumber; orderDetails.IceCreamId = model.IceCreamId; orderList.Add(orderDetails); } if (model.ToppingsId != 0) { var orderDetails = new OrderDetail(); orderDetails.OrderNumber = order.OrderNumber; orderDetails.IceCreamId = model.ToppingsId; orderList.Add(orderDetails); } order.OrderDetail = orderList; billingContext.Order.Add(order); billingContext.SaveChangesAsync(); return("Order Placed Successfully"); } catch (Exception) { throw; } }
public async Task<IActionResult> ClientEditor(int id, ClientViewModel model) { // Save Changes to the Database var oldclient = await _context.Clients.Where(c => c.Id == id) .Include(c=>c.Address) .FirstOrDefaultAsync().ConfigureAwait(true); if (oldclient != null) { // Update the Database _mapper.Map(model, oldclient); // Copy Changes if (await _context.SaveChangesAsync().ConfigureAwait(true) > 0) { return RedirectToAction("Index"); } } return View(); }
public async Task <IActionResult> OnPostBuy() { await InitializePage(); if (!ModelState.IsValid) { return(Page()); } ProcessCheckout(); try { await BillingContext.SaveChangesAsync(); } catch { ModelState.AddModelError("", "The selected seat is not longer available."); return(Page()); } return(RedirectToPage("/Billing/Checkout/Confirmed")); }