Пример #1
0
        public IActionResult FastOrder(Guid id, string firstName, string lastName, string phoneNumber)
        {
            bool isDataValid = this.ValidateFastOrderData(firstName, lastName, phoneNumber);

            if (!isDataValid)
            {
                return(BadRequest());
            }

            Order myOrder = new Order()
            {
                OrderDate   = DateTime.UtcNow.AddHours(+2),
                OrderStatus = OrderStatus.Confirmed
            };


            ordersService.AddOrder(myOrder);

            Product product = productsService.GetById(id);

            OrderItem item = new OrderItem()
            {
                ProductId = product.Id,
                Quantity  = 1,
                UnitPrice = product.Price,
                SubTotal  = product.Price
            };

            myOrder.OrderItems.Add(item);
            myOrder.PaymentMethod  = PaymentMethod.PayToCourier;
            myOrder.ShippingMethod = ShippingMethod.ToAddress;

            myOrder.TotalAmountInclTax = item.SubTotal;
            myOrder.TotalAmountExclTax = Math.Round(myOrder.TotalAmountInclTax / Constants.TaxAmount, 2);
            myOrder.TaxAmount          = myOrder.TotalAmountInclTax - myOrder.TotalAmountExclTax;

            if (myOrder.TotalAmountInclTax < Constants.MinPriceFreeShipping)
            {
                myOrder.ShippingTax = Constants.ShippingTax;
            }
            else
            {
                myOrder.ShippingTax = 0m;
            }

            ShortContactInfo contactInfo = new ShortContactInfo();

            contactInfo.FirstName   = firstName;
            contactInfo.LastName    = lastName;
            contactInfo.PhoneNumber = phoneNumber;


            ShortContactInfo newInfo = new ShortContactInfo()
            {
                FirstName   = firstName,
                LastName    = lastName,
                PhoneNumber = phoneNumber
            };

            newInfo.Orders.Add(myOrder);
            shortContactInfoService.Add(newInfo);

            ordersService.Update(myOrder);

            return(RedirectToAction("ShortOrderCompleted"));
        }
 public void Add(ShortContactInfo shortContactInfo)
 {
     this.shortContactInfo.Add(shortContactInfo);
     this.context.Commit();
 }