Пример #1
0
        public async Task InitDbWithFakeData_FromScratch()
        {
            var ordersRepositoryContext = new OrdersRepositoryContext(_ordersDbOptions);

            ordersRepositoryContext.Database.EnsureCreated();
            ordersRepositoryContext.Users.RemoveRange(ordersRepositoryContext.Users);
            ordersRepositoryContext.Orders.RemoveRange(ordersRepositoryContext.Orders);
            ordersRepositoryContext.OrderDetails.RemoveRange(ordersRepositoryContext.OrderDetails);
            ordersRepositoryContext.SaveChanges();

            if (!ordersRepositoryContext.Users.Any(x => x.Username == "atopuz"))
            {
                ordersRepositoryContext.Users.Add(new User
                {
                    Id        = Guid.NewGuid(),
                    FirstName = "ali",
                    LastName  = "topuz",
                    Username  = "******",
                    Password  = "******"
                });

                await ordersRepositoryContext.SaveChangesAsync();
            }

            Assert.True(true);
        }
Пример #2
0
        public async Task <IActionResult> Create([FromBody] OrderRequest model)
        {
            var order = _mapper.Map <Order>(model);

            order.GenerateNewId();
            order.UserId       = Guid.Parse(User.Identity.Name);
            order.CreationDate = DateTime.UtcNow;
            order.OrderStatus  = OrderStatus.Created;

            await _context.Orders.AddAsync(order);

            await _context.SaveChangesAsync();

            _orderCreateSender.SendCreatedOrder(order);

            return(Ok());
        }