예제 #1
0
        public IActionResult OnGetAction(Guid customerId, decimal shippingFee, int addressId)
        {
            int a = AddressId;

            DAL.Data.Entities.Order order = new DAL.Data.Entities.Order
            {
                Status       = OrderStatus.Pending,
                OrderDate    = DateTime.Now,
                DeliveryDate = DateTime.Now.AddDays(3),
                ShippingFee  = shippingFee,
                AddressId    = addressId
            };
            _orderRepository.Add(order);
            DAL.Data.Entities.Cart   cart  = _cartRepository.Find(c => c.CustomerId == customerId);
            IEnumerable <CartDetail> items = _cartDetailRepository.GetSome(i => i.CartId == cart.Id);

            foreach (CartDetail item in items)
            {
                OrderItem OrderItem = new OrderItem
                {
                    Quantity = item.Quantity,
                    ItemId   = item.ItemId,
                    OrderId  = order.Id,
                    Amount   = _itemRepository.Find(item.ItemId).Price *item.Quantity
                };
                _orderItemRepository.Add(OrderItem);
            }
            _cartDetailRepository.DeleteRange(items);
            return(RedirectToPage("./Success"));
        }
예제 #2
0
        public async Task <IActionResult> AddOrder(decimal totalPrice)
        {
            _cart = HttpHelper.HttpContext.Session.GetObjectFromJson <List <Item> >("Cart");

            string userId = (await userManager.GetUserAsync(HttpContext.User))?.Id;

            Order newOrder = new Order
            {
                User       = await userManager.FindByIdAsync(userId),
                Date       = DateTime.Now,
                TotalPrice = totalPrice / 100
            };

            _orderRepository.Add(newOrder);

            foreach (Item item in _cart)
            {
                var lastOrderItemId = _orderItemRepository.GetLastId();
                lastOrderItemId += 1;
                OrderItem newOrderItem = new OrderItem
                {
                    Id    = lastOrderItemId,
                    Order = newOrder
                };

                _orderItemRepository.Add(newOrderItem);
            }

            return(View("AddOrderSuccesfull"));
        }
예제 #3
0
        public async Task <IActionResult> MakeOrder(CreateOrderViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                OrderModel order             = new OrderModel();
                string     items_string_list = "";
                //When Created Id is +1 so in order of asigning it to the order item it needs to be decleared here
                int orderId = _orderRepository.OrdersCount();
                orderId++;

                //Add right order items to the database
                for (int i = 0; i < viewModel.OrderItems.Count; i++)
                {
                    viewModel.OrderItems[i].OrderId = orderId;
                    order.FullItemsAmmount         += viewModel.OrderItems[i].Ammount;
                    _orderItemRepository.Add(viewModel.OrderItems[i]);
                    items_string_list += $"Product: {viewModel.OrderItems[i].ProductName} | Quantity: {viewModel.OrderItems[i].Ammount} \n";
                }

                order.OrderDate    = DateTime.Now;
                order.SupplierName = viewModel.SupplierName;
                _orderRepository.AddOrder(order);

                SuppliersModel supplier = _supplierRepository.GetSupplier(viewModel.SupplierId);
                //Send email with order
                //await PostMail(supplier, order, items_string_list);

                return(RedirectToAction("DisplayOrders"));
            }
            return(View());
        }
예제 #4
0
        public Guid Create(OrderItemViewModel model)
        {
            _unitOfWork.BeginTransaction();
            var order = _orderRepository.GetById(model.Order.Id);

            if (order == null)
            {
                _unitOfWork.Commit();
                throw new Exception(ExceptionMessages.OrderException.NOT_FOUND);
            }

            var product = _productRepository.GetById(model.Product.Id);

            if (product == null)
            {
                _unitOfWork.Commit();
                throw new Exception(ExceptionMessages.ProductException.NOT_FOUND);
            }

            var orderItem = new OrderItem(order, product, model.Quantity);

            _orderItemRepository.Add(orderItem);
            _unitOfWork.Commit();
            return(orderItem.Id);
        }
예제 #5
0
 public ActionResult <OrderItem> Create([FromBody] OrderItem orderItem)
 {
     if (ModelState.IsValid)
     {
         OrderItemRepository.Add(orderItem);
     }
     return(CreatedAtAction(nameof(GetOrderItem), new { orderItem.OrderId }, orderItem));
 }
예제 #6
0
        public void Add(OrderItem orderItem)
        {
            _orderItemRepository.Add(orderItem);

            if (onItemAdded != null)
            {
                onItemAdded();
            }
        }
예제 #7
0
        public int ConfirmOrder(ref Cart cart)
        {
            var orderId = 0;

            using (var transacton = _ordersRepository.DataContext.Database.BeginTransaction())
            {
                try
                {
                    var order = new Order {
                        MemberId = cart.MemberId, OrderValue = cart.CartTotalPriceOut, CreationDate = DateTime.Now
                    };
                    _ordersRepository.Add(order);
                    _ordersRepository.DataContext.SaveChanges();

                    var orderOrderStatus = new OrderOrderStatus {
                        OrderId = order.OrderId, OrderOrderStatusId = (int)OrderStatusType.Confirmed, CreationDate = DateTime.Now
                    };
                    _orderOrderStatusRepository.Add(orderOrderStatus);
                    _orderOrderStatusRepository.DataContext.SaveChanges();

                    order.LatestOrderStatusId = orderOrderStatus.OrderOrderStatusId;
                    _ordersRepository.DataContext.SaveChanges();

                    if (order.OrderId > 0 && cart.Items != null)
                    {
                        foreach (var item in cart.Items)
                        {
                            var orderItem = new OrderItem
                            {
                                OrderId       = order.OrderId,
                                ProductId     = item.ProductId,
                                ProductCount  = item.ProductCount,
                                PriceOut      = item.PriceOut,
                                TotalPriceOut = item.TotalPriceOut,
                                CreationDate  = DateTime.Now
                            };

                            _orderItemRepository.Add(orderItem);
                            _orderItemRepository.DataContext.SaveChanges();
                        }
                    }

                    transacton.Commit();

                    ClearCart(ref cart);

                    orderId = order.OrderId;
                }
                catch (Exception)
                {
                    transacton.Rollback();
                }
            }

            return(orderId);
        }
        public async Task <IActionResult> PostOrderItem([FromBody] OrderItem orderItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _orderItems.Add(orderItem);

            return(CreatedAtAction("GetOrderItem", new { id = orderItem.OrderItemId }, orderItem));
        }
예제 #9
0
        public IActionResult Create([FromBody] OrderItem order)
        {
            if (order == null)
            {
                return(BadRequest());
            }


            _orderRepository.Add(order);

            return(CreatedAtRoute("GetOrder", new { id = order.IdOrder }, order));
        }
예제 #10
0
        public void Pay(List <OrderItemAddToOrderViewModel> model, Guid userId)
        {
            _unitOfWork.BeginTransaction();
            //sum price
            int orderPrice = 0;

            foreach (var item in model)
            {
                int quantity = item.Quantity;
                int price    = (int)item.Product.Price;
                orderPrice += price * quantity;
            }

            //get user from cookie
            var user = _userRepository.GetById(userId);

            if (user == null)
            {
                _unitOfWork.Commit();
                throw new Exception(ExceptionMessages.UserException.NOT_FOUND);
            }

            //create new empty order
            var order = new Order(user, OrderStatus.PAID, DateTime.Now, orderPrice);

            _orderRepository.Add(order);

            //add order items in created order
            foreach (var item in model)
            {
                var product = _productRepository.GetById(item.Product.Id);

                if (product == null)
                {
                    _unitOfWork.Commit();
                    throw new Exception(ExceptionMessages.ProductException.NOT_FOUND);
                }

                var orderItem = new OrderItem(order, product, item.Quantity);

                if (orderItem.Quantity > product.Quantity)
                {
                    _unitOfWork.Rollback();
                    throw new Exception(ExceptionMessages.OrderItemException.OUT_OF_STOCK);
                }
                _orderItemRepository.Add(orderItem);

                product.Quantity = product.Quantity - orderItem.Quantity;
                _productRepository.Update(product);
            }
            _unitOfWork.Commit();
        }
예제 #11
0
        public OrderItem RecordOrderItem(License license, PurchaseRecord purchaseRecord, int itemNumber)
        {
            OrderItem item = new OrderItem()
            {
                OrderItemNo      = itemNumber,
                PurchaseRecordId = purchaseRecord.Id,
                ActivationKey    = license.ActivationKey,
                LicenseId        = license.LicenseId
            };

            _orderItemRepository.Add(item);
            return(item);
        }
        public string GenerateOrders(int count)
        {
            var products = inventoryRepository.Fetch(0, int.MaxValue);

            if (null == products || products.Count == 0)
            {
                return("Products must first be added to the catalog.");
            }
            var contractors = contractorRepository.Fetch(0, int.MaxValue);

            if (null == contractors || contractors.Count == 0)
            {
                return("Products with Contractors must first be added to the catalog.");
            }
            var users = userRepository.GetUsers();

            if (null == users || users.Count == 0)
            {
                return("Users must first be added to the system.");
            }
            Random        random         = new Random((int)DateTime.Now.Ticks);
            StringBuilder result         = new StringBuilder();
            int           orderCount     = 0;
            int           orderItemCount = 0;
            HashSet <int> includedItems  = new HashSet <int>();

            for (int i = 0; i < count; i++)
            {
                orderCount++;
                int   itemCount = random.Next(10) + 1;
                Order order     = BuildRandomOrder(random, users);
                orderRepository.Add(order);
                includedItems.Clear();
                for (int j = 0; j < itemCount; j++)
                {
                    orderItemCount++;
                    var       product = GetNextProduct(products, random, includedItems);
                    OrderItem item    = new OrderItem();
                    item.OrderId   = order.Id;
                    item.Price     = product.ContractPrice;
                    item.ProductId = product.Id;
                    item.Quantity  = 1 + random.Next(6);
                    orderItemRepository.Add(item);
                }
            }
            result.AppendFormat("Added {0} orders\r\n", orderCount);
            result.AppendFormat("Added {0} order items\r\n", orderItemCount);
            return(result.ToString());
        }
예제 #13
0
        public OrderDTO SubmitOrder(OrderDTO model, string operatorId)
        {
            using (ITransactionCoordinator coordinator = new TransactionCoordinator(_dbUnitOfWork, _eventBus))
            {
                var orderItems = model.OrderItems?.Select(item => new OrderItem {
                    Count = item.Count, ObjectId = item.ObjectId, ObjectNo = item.ObjectNo, OrderId = item.OrderId, PreviewPictureUrl = item.PreviewPictureUrl, SelectedProperties = item.SelectedProperties, Title = item.Title, TradeUnitPrice = item.TradeUnitPrice
                })?.ToList();

                var obj = OrderFactory.CreateOrder(
                    model.TotalAmount,
                    model.ShippingCost,
                    model.PreferentialAmount,
                    model.Tax, model.PayAmount,
                    model.CustomerName,
                    model.CustomerMobile,
                    model.InvoiceType,
                    model.CustomerAddress,
                    orderItems,
                    operatorId,
                    model.Mark,
                    model.OrganizationId,
                    model.InvoiceRemark,
                    model.Remark,
                    model.ActivityId,
                    model.Title);

                _orderRepository.Add(obj);

                orderItems.ForEach(oi =>
                {
                    oi.OrderId = obj.Id;
                    _orderItemRepository.Add(oi);
                });

                obj.ConfirmSubmited();

                coordinator.Commit();

                model.Id = obj.Id;

                return(model);
            }
        }
예제 #14
0
        public async Task <Response> Create(CreateOrderItemRequest request)
        {
            try
            {
                var item = _mapper.Map <OrderItem>(request);

                _repository.Add(item);

                if (await _repository.SaveChangesAsync())
                {
                    var response = _mapper.Map <OrderItemResponse>(item);
                    return(OkResponse(null, response));
                }

                return(BadRequestResponse("Erro desconhecido."));
            }
            catch (Exception ex)
            {
                return(BadRequestResponse(ex.Message));
            }
        }
예제 #15
0
        public IActionResult Create([FromBody] JObject data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Order model = data["order"].ToObject <Order>();

            _service.Add(model);
            var list_item = data["order_item"].ToList();

            foreach (var item in list_item)
            {
                OrderItem model_item = item.ToObject <OrderItem>();
                _service_item.Add(model_item);
                Product model_product = _service_product.GetSingleByCondition(c => c.ProductID == model_item.ProductID);
                model_product.Quantity -= model_item.Quantity;
                _service_product.Update(model_product);
            }

            return(Ok(model));
        }
예제 #16
0
        public void Add(OrderItemDTO orderItemDto)
        {
            var orderItem = Mapper.Map <OrderItemDTO, OrderItem>(orderItemDto);

            _repository.Add(orderItem);
        }
예제 #17
0
 public void Post([FromBody] OrderItem value)
 => _orderItemRepository.Add(value);
예제 #18
0
 public void Add(OrderItem obj)
 {
     _OrderItemRepository.Add(obj);
 }
예제 #19
0
파일: Facade.cs 프로젝트: mtsiberev/eShop
 //------------------OrderItems methods
 public void AddOrderItem(OrderItem orderItem)
 {
     m_orderItemsRepository.Add(orderItem);
 }
예제 #20
0
 public void CreateOrderItem(OrderItem orderItem)
 {
     orderItemRepository.Add(orderItem);
     SaveOrderItem();
 }
예제 #21
0
 public int AddOrderItem(OrderItem entity)
 {
     return(_orderItemRepository.Add(entity));
 }
        public Order Create(int shoppingCartId, int userId, OrderPaymentMethod paymentMethod, string address1, string address2, string address3, string city, string state, string postalCode, string emailAddress)
        {
            var cart = _shoppingCartRepository.Get(shoppingCartId);

            if (cart == null)
            {
                throw new Exception("Shopping cart not found.");
            }

            if (userId != cart.UserId)
            {
                throw new Exception("Shopping cart not found.");
            }

            var cartItems = _shoppingCartItemRepository.Fetch(shoppingCartId);

            if (cartItems == null || !cartItems.Any())
            {
                throw new Exception("No items found in shopping cart.");
            }

            Order newOrder = new Order()
            {
                Items         = new List <OrderItem>(),
                CreateDate    = DateTime.UtcNow,
                PaymentMethod = paymentMethod,
                Status        = OrderStatus.Placed,
                UserId        = cart.UserId,
                Address1      = address1,
                Address2      = address2,
                Address3      = address3,
                City          = city,
                State         = state,
                PostalCode    = postalCode,
                EmailAddress  = emailAddress
            };

            foreach (var item in cartItems)
            {
                OrderItem orderItem = new OrderItem()
                {
                    ProductId = item.ProductId,
                    Quantity  = item.Quantity,
                    Price     = item.Price
                };

                newOrder.Items.Add(orderItem);
            }

            _orderRepository.Add(newOrder);

            foreach (var orderItem in newOrder.Items)
            {
                orderItem.OrderId = newOrder.Id;
                _orderItemRepository.Add(orderItem);
            }

            foreach (var cartItem in cartItems)
            {
                _shoppingCartItemRepository.Delete(cartItem.Id);
            }

            return(newOrder);
        }