public async Task <IActionResult> Create([Bind("CustomerId,CustomerName,CustomerLastName,CustomerPhone,CustomerEmail,CustomerStatus,CustomerCreated")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("ProductId,ProductName,Description,Stock,ProductCreated,ProductStatus")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("CustomerOrderId,ProductId,CustomerId,OrderCreated,OrderStatus")] CustomerOrder customerOrder) { if (ModelState.IsValid) { _context.Add(customerOrder); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "CustomerEmail", customerOrder.CustomerId); ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "Description", customerOrder.ProductId); return(RedirectToAction("Index", "Customers")); }
public async Task <ActionResult> RegisterAsync([FromBody] RegisterCustomer command) { try { if (ModelState.IsValid) { Customer customer = command.MapToCustomer(); _dbContext.Customers.Add(customer); await _dbContext.SaveChangesAsync(); CustomerRegistered e = command.MapToCustomerRegistered(); await _messagePublisher.PublishMessageAsync(e.MessageType, e, ""); return(CreatedAtRoute("GetByCustomerId", new { customerId = customer.CustomerId }, customer)); } return(BadRequest()); } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task CommitAsync() { await _db.SaveChangesAsync(); }