コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
 public async Task CommitAsync()
 {
     await _db.SaveChangesAsync();
 }