コード例 #1
0
        public int AddOrder([FromBody] AddOrderRequestModel requestModel)
        {
            var existingOrder = Context.Orders.FirstOrDefault(o => o.OrderNo == requestModel.OrderNo);
            var vatTax        = Context.TaxRates.First(r => r.TaxCode == OrdersConstants.VatTaxCode && r.StartDate.Date <= DateTime.Now.Date && r.EndDate.Date >= DateTime.Now.Date);

            if (existingOrder != null)
            {
                return(existingOrder.OrderId);
            }

            var newOrder = new OrderHead
            {
                OrderNo          = requestModel.OrderNo,
                SubTotal         = 0M,
                VatTotal         = 0M,
                DiscountTotal    = 0M,
                OrderTotal       = 0M,
                VatRate          = vatTax.Rate,
                CompanyProfileId = requestModel.CompanyProfileId,
                Status           = OrdersConstants.InProgressStatus,
                CreateDate       = DateTime.Now,
                CreateUser       = requestModel.Username
            };

            Context.Orders.Add(newOrder);

            if (requestModel.CompanyProfileId != 0)
            {
                Context.CompanyProfiles.First(cp => cp.CompanyProfileId == requestModel.CompanyProfileId).OrderNoSeed += 1;
            }

            Context.SaveChanges();

            return(newOrder.OrderId);
        }
コード例 #2
0
        public void AddOrder_ReturnsOrderIdInt()
        {
            // given
            var          resources    = new Resources();
            const string orderNo      = "TestQuote123";
            const string username     = "******";
            const int    orderId      = 101010;
            var          requestModel = new AddOrderRequestModel {
                OrderNo = orderNo, Username = username, CompanyProfileId = 1
            };

            resources.MockApiCaller.AddMockResponse("WebApi:Orders:AddOrder", requestModel, orderId);

            // when
            var result = resources.Controller.AddOrder(orderNo) as JsonResult;

            // then
            Assert.IsNotNull(result);
            Assert.AreEqual(orderId, result.Value);
        }
コード例 #3
0
 public IHttpActionResult Post([FromBody] AddOrderRequestModel request)
 {
     OrderBook.AddOrder(request.IsBuyOrder, request.Amount, request.Count, request.UserId);
     return(Ok());
 }