public async Task Should_Return_Error_Message_When_Parking_Lot_Is_Full()
        {
            // given
            var client        = GetClient();
            var parkingLotDto = new ParkingLotDto()
            {
                Name     = "parkinglot1",
                Capacity = 0,
                Location = "Beijing",
            };

            var           parkingLotContent = JsonConvert.SerializeObject(parkingLotDto);
            StringContent parkingLotcontent = new StringContent(parkingLotContent, Encoding.UTF8, MediaTypeNames.Application.Json);
            // when
            await client.PostAsync("/parkinglots", parkingLotcontent);

            var orderCreateDto = new OrderCreateDto()
            {
                ParkingLotName = "parkinglot1",
                PlateNumber    = "abc123",
            };
            var           httpContent = JsonConvert.SerializeObject(orderCreateDto);
            StringContent content     = new StringContent(httpContent, Encoding.UTF8, MediaTypeNames.Application.Json);
            // when
            var postResponse = await client.PostAsync("/orders", content);

            var body = await postResponse.Content.ReadAsStringAsync();

            // then
            Assert.Equal("The parking lot is full", body);
        }
コード例 #2
0
ファイル: ConcertTest.cs プロジェクト: MassimoC/PaaSTicketing
        public async Task PlaceNewOrder_TestAsync()
        {
            //Arrange
            var userGuid = Guid.NewGuid().ToString();
            var newUser  = new UserCreateDto
            {
                Firstname = String.Format("user{0}", userGuid),
                Lastname  = "Test user",
                Phone     = "000001111",
                Email     = "*****@*****.**"
            };
            var requestUser  = TestExtensions.GetJsonRequest(newUser, "POST", $"/core/v1/users/");
            var responseUser = await fixture._httpClient.SendAsync(requestUser);

            responseUser.StatusCode.Should().Be(HttpStatusCode.Created);

            var obj      = JsonConvert.DeserializeObject <User>(responseUser.Content.ReadAsStringAsync().Result);
            var newOrder = new OrderCreateDto
            {
                UserId     = obj.UserId,
                ConcertId  = new Guid("6df7cee9-7081-41ce-947b-c305a33a3888"),
                TicketDate = DateTime.Now
            };
            var request = TestExtensions.GetJsonRequest(newOrder, "POST", $"/core/v1/orders/");
            //Act
            var response = await fixture._httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.Created);
        }
コード例 #3
0
        public async Task <IActionResult> AddressAndPayment(
            [FromServices] ICartService cartService,
            [FromForm] OrderCreateDto orderCreateDto,
            CancellationToken requestAborted)
        {
            if (!ModelState.IsValid)
            {
                return(View(orderCreateDto));
            }

            IFormCollection formCollection = await HttpContext.Request.ReadFormAsync();

            try
            {
                //if (string.Equals(formCollection["PromoCode"].FirstOrDefault(), PromoCode, StringComparison.OrdinalIgnoreCase) == false) return View(orderCreateDto);

                orderCreateDto.Username = $"{orderCreateDto.FirstName}{orderCreateDto.LastName}";
                orderCreateDto.BasketId = cartService.GetBasketId();

                await cartService.Checkout(orderCreateDto);

                _logger.LogInformation($"User {orderCreateDto.Username} started checkout of {orderCreateDto.OrderId}.");
                TempData[ToastrMessage.Success] = "Thank you for your order";

                return(RedirectToAction("index", "Home"));
            }
            catch
            {
                ModelState.AddModelError("", "An error occured whil processing order");
                //Invalid - redisplay with errors
                return(View(orderCreateDto));
            }
        }
コード例 #4
0
        public async Task <(OrderDto, string)> AddAsync(OrderCreateDto orderCreateDto)
        {
            var parkingLot = this.parkingLotContext.ParkingLots
                             .FirstOrDefault(_ => _.Name == orderCreateDto.ParkingLotName);

            if (parkingLot == null)
            {
                return(null, "the parking lot not found");
            }

            if (parkingLot.AvailablePosition <= 0)
            {
                return(null, "the parking lot is full");
            }

            var newOrder = new OrderEntity(orderCreateDto);

            if (this.parkingLotContext.Orders.Any(order =>
                                                  order.PlateNumber == newOrder.PlateNumber && order.Status == OrderStatus.Open))
            {
                return(null, "the car is already parked, check plate number");
            }

            await this.parkingLotContext.Orders.AddAsync(newOrder);

            parkingLot.AvailablePosition -= 1;
            await this.parkingLotContext.SaveChangesAsync();

            return(new OrderDto(newOrder), string.Empty);
        }
コード例 #5
0
        public void Execute(OrderCreateDto request)
        {
            _validator.ValidateAndThrow(request);
            var order = new Order
            {
                UserId    = _actor.Id,
                Address   = request.Address,
                OrderDate = request.OrderDate
            };

            foreach (var item in request.Items)
            {
                var product = _context.Products.Find(item.ProductId);

                product.Quantity -= item.Quantity;

                order.OrderLines.Add(new OrderLine
                {
                    ProductId = item.ProductId,
                    Quantity  = item.Quantity,
                    Name      = product.Name,
                    Price     = (decimal)product.Price
                });
            }
            _context.Orders.Add(order);
            _context.SaveChanges();
        }
コード例 #6
0
        public ActionResult <OrderItemDto> AddOrder([FromBody] OrderCreateDto orderCreateDto)
        {
            if (orderCreateDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            OrderItem toAdd = Mapper.Map <OrderItem>(orderCreateDto);

            _orderRepository.Add(toAdd);

            if (!_orderRepository.Save())
            {
                throw new Exception("Creating a orderitem failed on save.");
            }

            OrderItem orderItem = _orderRepository.GetSingle(toAdd.Order_Num);

            return(CreatedAtRoute(nameof(GetSingleOrder), new { order_num = orderItem.Order_Num },
                                  Mapper.Map <OrderItemDto>(orderItem)));
        }
コード例 #7
0
        public async Task <ActionResult> CreateOrderAsync([FromBody] OrderCreateDto model, CancellationToken cancellationToken = default)
        {
            var command = _mapper.Map <OrderCreateCommand>(model);
            var result  = await _mediator.Send(command, cancellationToken);

            return(CreatedAtRoute(nameof(GetOrderAsync), new { orderId = result }, result));
        }
コード例 #8
0
ファイル: OrderService.cs プロジェクト: dimaLytvyniuk/OTP3
        public async Task <OrderDetailsDto> CreateOrder(OrderCreateDto orderDto)
        {
            using (_unitOfWork)
            {
                var orderRepository   = _unitOfWork.OrderRepository;
                var userRepository    = _unitOfWork.UserRepository;
                var productRepository = _unitOfWork.ProductRepository;

                var order = _mapper.Map <OrderCreateDto, Order>(orderDto);
                var user  = await userRepository.FindAsync(x => x.Email == orderDto.UserEmail);

                var product = await productRepository.FindAsync(x => x.Id == orderDto.ProductId);

                if (user == null || product == null)
                {
                    return(null);
                }

                order.User    = user;
                order.Product = product;
                order.Date    = DateTime.Now.ToUniversalTime();

                if (product.Quantity >= order.Quantity)
                {
                    order.IsDone      = true;
                    product.Quantity -= order.Quantity;
                }

                orderRepository.Add(order);
                await _unitOfWork.SaveAsync();

                return(await GetOrder(order.Id));
            }
        }
コード例 #9
0
 public OrderEntity(OrderCreateDto orderCreateDto)
 {
     ParkingLotName     = orderCreateDto.ParkingLotName;
     PlateNumber        = orderCreateDto.PlateNumber;
     CreationTimeOffset = DateTimeOffset.Now;
     CloseTimeOffset    = null;
     Status             = OrderStatus.Open;
 }
コード例 #10
0
        //[ValidateAntiForgeryToken]
        public JsonResult Create(OrderCreateDto order)
        {
            var result = service.Create(order, SchoolUser);

            // 如果有缓存,注意在这里要清空缓存

            return(Json(result));
        }
コード例 #11
0
 public OrderEntity(OrderCreateDto orderDto)
 {
     OrderNumber    = Guid.NewGuid().ToString();
     ParkingLotName = orderDto.ParkingLotName;
     PlateNumber    = orderDto.PlateNumber;
     CreationTime   = DateTime.Now;
     Status         = OrderStatus.Open;
 }
コード例 #12
0
ファイル: OrderService.cs プロジェクト: a498497672/Ticket
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="orderCreateDto"></param>
        /// <returns></returns>
        public Tbl_Order Create(OrderCreateDto orderCreateDto)
        {
            _weiXinUserService.BindWeChatAcount(orderCreateDto.OpenId, orderCreateDto.Mobile, orderCreateDto.Verifycode);
            var tbl_Ticket = _ticketService.Get(orderCreateDto.TravelTime, orderCreateDto.TicketId);
            var tbl_Order  = AddOrder(orderCreateDto, tbl_Ticket);

            _orderDetailService.Add(tbl_Order, tbl_Ticket);
            return(tbl_Order);
        }
コード例 #13
0
        /// <summary>
        /// Creates an order.
        /// </summary>
        /// <param name="model">The order to be created.</param>
        /// <returns>The details of the order created.</returns>
        public OrderDetailDto CreateOrder(OrderCreateDto model)
        {
            Order order = new(model);

            // The OrderId is set at the store level. Since it is a reference type, the ID carries over.
            this._orderStore.AddOrder(order);

            return(new OrderDetailDto(order));
        }
コード例 #14
0
        public async Task <ActionResult> Create(OrderCreateDto model)
        {
            var result = await _orderService.Create(model);

            return(CreatedAtAction(
                       "GetById",
                       new { id = result.OrderId },
                       result
                       ));
        }
コード例 #15
0
        public ActionResult Create(OrderCreateDto model)
        {
            var result = _orderService.Create(model);

            return(CreatedAtAction(
                       "GetById",
                       new { id = result.OrderId },
                       result
                       ));
        }
コード例 #16
0
        public ActionResult <OrderReadDto> AddNewOrder([FromBody] OrderCreateDto orderCreateDto)
        {
            var orderReadDto = this._orderService.AddNewOrder(orderCreateDto);

            if (orderReadDto == null)
            {
                return(this.BadRequest());
            }

            return(this.CreatedAtRoute(new { Id = orderReadDto.OrderId }, orderReadDto));
        }
コード例 #17
0
        public async Task <IActionResult> CreateAsync(
            [FromBody][CustomizeValidator(RuleSet = "Create")]
            OrderCreateDto orderDto)
        {
            var order = await _orderService.CreateAsync(orderDto);

            await _notificationService.NoticeByEmployeeIdAsync(order.EmployeeId,
                                                               $"You've got new task \"{order.BriefTask}\"!");

            return(Ok(order));
        }
コード例 #18
0
        public async Task <ActionResult <string> > CreateOrder(OrderCreateDto orderCreateDto)
        {
            if (!await orderService.CanPark(orderCreateDto.ParkingLotName))
            {
                return(BadRequest("The parking lot is full"));
            }

            var number = await orderService.AddOrder(orderCreateDto);

            return(CreatedAtAction(nameof(GetByNumber), new { number }, number));
        }
コード例 #19
0
ファイル: OrderService.cs プロジェクト: a498497672/Ticket
        /// <summary>
        /// 余额支付
        /// </summary>
        /// <param name="orderCreateDto"></param>
        public Tbl_Order BalancePay(OrderCreateDto orderCreateDto)
        {
            _weiXinUserService.BindWeChatAcount(orderCreateDto.OpenId, orderCreateDto.Mobile, orderCreateDto.Verifycode);
            var tbl_Ticket = _ticketService.Get(orderCreateDto.TravelTime, orderCreateDto.TicketId);
            var tbl_Order  = AddOrderForBalancePay(orderCreateDto, tbl_Ticket);

            _orderDetailService.AddForBalancePay(tbl_Order, tbl_Ticket);
            _weiXinUserService.UpdateForBalancePay(tbl_Order);
            _integralDetailsService.AddForBalanceConsumption(tbl_Order);
            return(tbl_Order);
        }
コード例 #20
0
        public ActionResult <OrderReadDto> CreateOrder(OrderCreateDto orderCreateDto)
        {
            var orderModel = _mapper.Map <order>(orderCreateDto);

            _order.CreateOrder(orderModel);
            _order.SaveChanges();

            var orderReadDto = _mapper.Map <OrderReadDto>(orderModel);

            return(CreatedAtRoute(nameof(GetOrderById), new { Id = orderReadDto.OrderId }, orderReadDto));
        }
コード例 #21
0
        public ActionResult Create(OrderCreateDto model)
        {
            var result = _orderService.Create(model);

            return(new JsonResult(new
            {
                Message = "Su Pedido se ha realizado correctamente. Espere aproximadamente "
                          + _orderService.GetAverageTime()
                          + " para recibir su orden",
                DetalleDeOrden = result
            }));
        }
コード例 #22
0
ファイル: WxPayController.cs プロジェクト: a498497672/Ticket
        public IHttpActionResult PostBalancePay(OrderCreateDto orderCreateDto)
        {
            if (!ModelState.IsValid)
            {
                var message = ModelState.BuildErrorMessage();
                throw new SimplePromptException(message);
            }
            var orderNo = _orderFacadeService.BalancePay(orderCreateDto);
            var result  = new TResult <string>();

            return(Ok(result.SuccessResult(orderNo)));
        }
コード例 #23
0
        /// <summary>
        /// 余额支付 返回订单号
        /// </summary>
        /// <param name="orderCreateDto"></param>
        /// <returns></returns>
        public string BalancePay(OrderCreateDto orderCreateDto)
        {
            var tbl_Order = new Tbl_Order();

            //余额支付
            using (var unitOfWork = new UnitOfWork())
            {
                tbl_Order = _orderService.BalancePay(orderCreateDto);
                unitOfWork.Commit();
            }
            return(tbl_Order.OrderNo);
        }
コード例 #24
0
        public async Task <OrderDto> Create(OrderCreateDto model)
        {
            var entry = _mapper.Map <Order>(model);

            entry.RegisteredAt = DateTime.Now;
            entry.StateId      = StateHelper.Pendiente;

            await _context.AddAsync(entry);

            await _context.SaveChangesAsync();

            return(_mapper.Map <OrderDto>(entry));
        }
コード例 #25
0
        public async Task <bool> Checkout(OrderCreateDto orderCreateDto)
        {
            var response = await _restClient.PostAsync <dynamic>($"{baseUrl}/checkout", orderCreateDto);

            if (response.HttpResponseMessage.IsSuccessStatusCode)
            {
                await _restClient.DeleteAsync($"{baseUrl}/{orderCreateDto.BasketId}");

                SetBasketId();
            }

            return(response.HttpResponseMessage.IsSuccessStatusCode);
        }
コード例 #26
0
        public OrderReadDto AddNewOrder(OrderCreateDto orderCreateDto)
        {
            var newOrderModel = this._mapper.Map <Order>(orderCreateDto);

            newOrderModel.OrderedAt = DateTime.Now;

            this._orderRepository.Add(newOrderModel);
            this._orderRepository.SaveChanges();

            var orderReadDto = this._mapper.Map <OrderReadDto>(newOrderModel);

            return(orderReadDto);
        }
コード例 #27
0
        public void Order_Constructor2_Pass()
        {
            OrderCreateDto createDto = TestValues.OrderCreateDto;

            // Execute SUT.
            Order sut = new(createDto);

            // Verify Results.
            Assert.Null(sut.OrderId);
            Assert.True(DateTimeOffset.UtcNow - sut.CreatedOn < TimeSpan.FromSeconds(1));
            Assert.Equal(createDto.Description, sut.Description);
            Assert.Null(sut.LastModOn);
            Assert.Equal(Status.Active, sut.Status);
        }
コード例 #28
0
        public OrderDto CreateOrder(OrderCreateDto orderCreate)
        {
            Pedido pedido = new Pedido
            {
                ClienteId = orderCreate.ClientId,
                UsuarioId = orderCreate.UserId,
                Fecha     = DateTime.Now
            };

            _galaxyTallerContext.Pedido.Add(pedido);
            _galaxyTallerContext.SaveChanges();

            return(GetOrder(pedido.PedidoId));
        }
コード例 #29
0
        public OrderDto Create(OrderCreateDto model)
        {
            var entry = _mapper.Map <Order>(model);

            PrepareDetail(entry.Items);
            PrepareHeader(entry);

            _context.Add(entry);
            _context.SaveChanges();

            return(_mapper.Map <OrderDto>(
                       GetById(entry.OrderId)
                       ));
        }
コード例 #30
0
        public async Task <string> AddOrder(OrderCreateDto orderCreateDto)
        {
            OrderEntity orderEntity = new OrderEntity(orderCreateDto);
            await parkingLotContext.Orders.AddAsync(orderEntity);

            var foundParkingLot =
                await parkingLotContext.ParkingLots.FirstOrDefaultAsync(parkingLot =>
                                                                        parkingLot.Name == orderCreateDto.ParkingLotName);

            foundParkingLot.Orders.Add(orderEntity);
            await parkingLotContext.SaveChangesAsync();

            return(orderEntity.OrderNumber);
        }