Ejemplo n.º 1
0
        public Order CreateOrder(Order newOrder, string userId)
        {
            var cart = GetCart();

            newOrder.OrderDate = DateTime.Now;
            // newOrder.userId = userId;

            _db.Orders.Add(newOrder);

            if (newOrder.OrderPositions == null)
            {
                newOrder.OrderPositions = new List <OrderPosition>();
            }
            decimal cartValue = 0;

            foreach (var cartItem in cart)
            {
                var newOrderPosition = new OrderPosition()
                {
                    SupplementId  = cartItem.Supplement.SupplementId,
                    Amount        = cartItem.Amount,
                    PurchasePrice = cartItem.Supplement.Price,
                };

                cartValue += (cartItem.Amount * cartItem.Supplement.Price);
                newOrder.OrderPositions.Add(newOrderPosition);
            }

            newOrder.OrderValue = cartValue;
            _db.SaveChanges();

            return(newOrder);
        }
Ejemplo n.º 2
0
        // GET: OrderPositions/CreateModal
        public async Task <ActionResult> CreateModal(int?orderId)
        {
            var order = await _repository.Order.Find(orderId);

            if (order == null)
            {
                return(HttpNotFound());
            }

            var position = new OrderPosition();

            position.OrderId = order.OrderId;

            if (order.Positions.Count == 0)
            {
                position.Position = 1;
            }
            else
            {
                position.Position = order.Positions.Last().Position + 1;
            }

            ViewBag.ProductId = new SelectList(await _repository.Product.GetAll(), "ProductId", "Name");

            return(PartialView("Partials/AddModal", position));
        }
        public Order CreateOrder(Order newOrder, string userId)
        {
            List <ShoppingCartPosition> shoppingCarts = GetShoppingCart();

            newOrder.AddingDate = clock.Now;
            newOrder.UserId     = userId;

            db.Orders.Add(newOrder);

            if (newOrder.OrderPositions == null)
            {
                newOrder.OrderPositions = new List <OrderPosition>();
            }

            foreach (var shoppingCartElement in shoppingCarts)
            {
                OrderPosition newOrderPosition = new OrderPosition()
                {
                    ProductVariantId = shoppingCartElement.ProductVariant.ProductVariantId,
                    Quantity         = shoppingCartElement.Quantity,
                    Price            = shoppingCartElement.Price
                };

                newOrder.OrderPositions.Add(newOrderPosition);
            }

            newOrder.Price = GetValueOfShoppingCart();
            db.SaveChangesWrapped();
            return(newOrder);
        }
Ejemplo n.º 4
0
        //Metoda tworzenia nowe zamowienie
        public Order CreateOrder(Order newOrder, string userId)
        {
            var cart = GetCart();

            newOrder.DateOfAddition = DateTime.Now;
            newOrder.UserId         = userId;

            //dodanie zamówienia
            db.Orders.Add(newOrder);

            //dodanie pozycji zamowienia
            if (newOrder.OrderPosition == null)
            {
                newOrder.OrderPosition = new List <OrderPosition>();
            }

            decimal cartValue = 0;

            foreach (var cartElement in cart)
            {
                //tworzenie nowej pozycji zamowienia
                var newPositionOrder = new OrderPosition()
                {
                    ProductId     = cartElement.Product.ProductId,
                    Amount        = cartElement.Amount,
                    PurchasePrice = cartElement.Product.Price
                };

                cartValue += (cartElement.Amount * cartElement.Product.Price);
                newOrder.OrderPosition.Add(newPositionOrder);
            }
            newOrder.OrderValue = cartValue;
            db.SaveChanges();
            return(newOrder);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Title,Quantity,Price,OrderID,AttachmentPath,Description,ID,NrIntern,UserID,CreateBy,UpdateBy,CreateDate,UpdateDate,OrganizationID,Remark,Deleted")] OrderPosition orderPosition)
        {
            if (id != orderPosition.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(orderPosition);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderPositionExists(orderPosition.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderID"] = new SelectList(_context.Orders, "ID", "NrIntern", orderPosition.OrderID);
            return(View(orderPosition));
        }
Ejemplo n.º 6
0
        private string GetPricePositionName(OrderPosition orderPosition)
        {
            var builder = new StringBuilder();

            builder.Append(orderPosition.PricePosition.Name);

            if (orderPosition.PricePosition.PricePositionTypeId == 26)
            {
                return(builder.ToString());
            }

            if (orderPosition.PricePosition.PricePositionType.EnableSecondSize)
            {
                builder.Append(
                    string.Format(" ({0}x{1} {2})",
                                  orderPosition.PricePosition.FirstSize,
                                  orderPosition.PricePosition.SecondSize,
                                  orderPosition.PricePosition.Unit.Name)
                    );
            }
            else
            {
                builder.Append(
                    string.Format(" ({0} {1})",
                                  orderPosition.PricePosition.FirstSize,
                                  orderPosition.PricePosition.Unit.Name)
                    );
            }

            builder.Append(string.Format(" {0}", orderPosition.PricePosition.Description));

            return(builder.ToString().Trim());
        }
Ejemplo n.º 7
0
        public Order CreateOrder(Order newOrder, string userId)
        {
            var cart = DownloadCart();

            newOrder.DateAdded = DateTime.Now;

            newOrder.UserId = userId;

            db.Orders.Add(newOrder);

            if (newOrder.OrderPosition == null)
            {
                newOrder.OrderPosition = new List <OrderPosition>();
            }
            decimal cartValue = 0;

            foreach (var item in cart)
            {
                var newOrderPosition = new OrderPosition()
                {
                    CourseId  = item.Course.CourseId,
                    Volume    = item.Number,
                    OrderCost = item.Value
                };

                cartValue += (item.Number * item.Course.CoursePrice);
                newOrder.OrderPosition.Add(newOrderPosition);
            }

            newOrder.OrderValue = cartValue;
            db.SaveChanges();

            return(newOrder);
        }
Ejemplo n.º 8
0
        private string GetAccountNumenclature(OrderPosition orderPosition)
        {
            string nomenclature;

            if (orderPosition.PricePosition.IsShowSize)
            {
                nomenclature = orderPosition.PricePosition.PricePositionType.EnableSecondSize
                    ? string.Format("{0} - {1} {2} ({3}x{4} {5}) {6}",
                                    orderPosition.Supplier.Company.Name,
                                    orderPosition.Supplier.City.Name,
                                    orderPosition.PricePosition.Name,
                                    orderPosition.PricePosition.FirstSize,
                                    orderPosition.PricePosition.SecondSize,
                                    orderPosition.PricePosition.Unit.Name,
                                    orderPosition.PricePosition.Description ?? string.Empty)
                    : string.Format("{0} - {1} {2} ({3} {4}) {5}",
                                    orderPosition.Supplier.Company.Name,
                                    orderPosition.Supplier.City.Name,
                                    orderPosition.PricePosition.Name,
                                    orderPosition.PricePosition.FirstSize,
                                    orderPosition.PricePosition.Unit.Name,
                                    orderPosition.PricePosition.Description ?? string.Empty);
            }
            else
            {
                nomenclature = string.Format("{0} - {1} {2} {3}",
                                             orderPosition.Supplier.Company.Name,
                                             orderPosition.Supplier.City.Name,
                                             orderPosition.PricePosition.Name,
                                             orderPosition.PricePosition.Description ?? string.Empty);
            }

            return(nomenclature);
        }
Ejemplo n.º 9
0
        public OrderPosition SetOrderPosition(OrderPosition orderPosition, bool isUnloaded, bool isActual, DbTransaction dbTran)
        {
            var orderPositionId = orderPosition.Id;
            var lastEditDate    = orderPosition.BeginDate;

            SetOrderPosition(
                dbTran: dbTran,
                id: ref orderPositionId,
                orderId: orderPosition.OrderId,
                parentOrderPositionId: orderPosition.ParentOrderPositionId,
                supplierId: orderPosition.SupplierId,
                priceId: orderPosition.PriceId,
                pricePositionId: orderPosition.PricePositionId,
                pricePositionVersionDate: orderPosition.PricePositionVersion,
                clientDiscount: orderPosition.Discount,
                markup: orderPosition.Markup,
                nds: orderPosition.Nds,
                compensation: orderPosition.Compensation,
                description: orderPosition.Description,
                clientPackageDiscount: orderPosition.ClientPackageDiscount,
                editUserId: _editUserId,
                isActual: isActual,
                lastEditDate: ref lastEditDate,
                isUnloaded: isUnloaded,
                needConfirmation: orderPosition.NeedConfirmation);

            orderPosition.Id        = orderPositionId;
            orderPosition.BeginDate = lastEditDate;

            _context.Entry(orderPosition).Reload();

            return(orderPosition);
        }
Ejemplo n.º 10
0
        internal void StoreToXml(
            Project project,
            XmlElement parentNode)
        {
            if (parentNode.OwnerDocument != null)
            {
                var a = parentNode.OwnerDocument.CreateAttribute(@"name");
                a.Value = Name;
                parentNode.Attributes.Append(a);

                a       = parentNode.OwnerDocument.CreateAttribute(@"projectFolderUniqueID");
                a.Value = _projectFolderUniqueID.ToString();
                parentNode.Attributes.Append(a);

                a       = parentNode.OwnerDocument.CreateAttribute(@"orderPosition");
                a.Value = OrderPosition.ToString();
                parentNode.Attributes.Append(a);

                a       = parentNode.OwnerDocument.CreateAttribute(@"viewMode");
                a.Value = Mode.ToString();
                parentNode.Attributes.Append(a);

                var remarksNode =
                    parentNode.OwnerDocument.CreateElement(@"remarks");
                parentNode.AppendChild(remarksNode);
                remarksNode.InnerText = Remarks;

                if (parentNode.OwnerDocument != null)
                {
                    a       = parentNode.OwnerDocument.CreateAttribute(@"uniqueID");
                    a.Value = _uniqueID.ToString();
                    parentNode.Attributes.Append(a);
                }
            }
        }
Ejemplo n.º 11
0
        public static void UpdateOrder(this Order entity, OrderModel viewModel)
        {
            entity.CustomerNumber = viewModel.CustomerNumber;
            entity.OrderDate      = viewModel.OrderDate;
            entity.DeliveryDate   = viewModel.DeliveryDate;

            if (viewModel.OrderPositions != null)
            {
                if (entity.OrderPositions == null)
                {
                    entity.OrderPositions = new List <OrderPosition>();
                }

                foreach (OrderPositionModel pos in viewModel.OrderPositions)
                {
                    var posEntity = entity.OrderPositions.SingleOrDefault(x => x.ID == pos.PositionOrderId);
                    if (posEntity == null || posEntity.ID == 0)
                    {
                        posEntity = new OrderPosition();
                        posEntity.UpdateOrderPosition(pos);
                        entity.OrderPositions.Add(posEntity);
                    }
                    else
                    {
                        posEntity.UpdateOrderPosition(pos);
                    }
                }
            }

            entity.TotalPrice = entity.OrderPositions.Sum(x => x.Total);
        }
Ejemplo n.º 12
0
        public Order CreateOrder(Order newOrder, string userId)
        {
            var basket = DownloadBasket();

            newOrder.DateAdded = DateTime.Now;
            newOrder.UserId    = userId;

            db.Orders.Add(newOrder);

            if (newOrder.OrderPositions == null)
            {
                newOrder.OrderPositions = new List <OrderPosition>();
            }
            decimal basketValue = 0;

            foreach (var basketItem in basket)
            {
                var newOrderPosition = new OrderPosition()
                {
                    ProductID     = basketItem.Product.ProductID,
                    Quantity      = basketItem.Quantity,
                    PurchasePrice = basketItem.Product.Price
                };

                basketValue += (basketItem.Quantity * basketItem.Product.Price);
                newOrder.OrderPositions.Add(newOrderPosition);
            }

            newOrder.OrderValue = basketValue;
            db.SaveChanges();

            return(newOrder);
        }
Ejemplo n.º 13
0
        public Order CreateOrder(Order neworder, string userId)
        {
            var cart = GetCart();

            neworder.OrderTime = DateTime.Now;
            neworder.UserId    = userId;

            _db.Orders.Add(neworder);


            if (neworder.OrderPositions == null)
            {
                neworder.OrderPositions = new List <OrderPosition>();
            }
            decimal cartValue = 0;

            foreach (var cartElement in cart)
            {
                var newOrderPosition = new OrderPosition()
                {
                    ProductId  = cartElement.Product.ProductId,
                    Amount     = cartElement.Amount,
                    OrderPrice = cartElement.Product.Price
                };

                cartValue += cartElement.Amount * cartElement.Product.Price;
                neworder.OrderPositions.Add(newOrderPosition);
            }

            neworder.OrderValue = cartValue;
            _db.SaveChanges();

            return(neworder);
        }
Ejemplo n.º 14
0
 public static void UpdateOrderPosition(this OrderPosition entity, OrderPositionModel model)
 {
     entity.PositionNumber = model.PositionNumber;
     entity.Pieces         = model.Pieces;
     entity.Text           = model.Text;
     entity.Price          = model.Price;
     entity.Total          = model.PositionNumber * model.Price;
 }
Ejemplo n.º 15
0
        public async Task <ActionResult <OrderPosition> > PostOrderPosition(CreateOrderPositionDTO orderpositionDTO)
        {
            var orderposition = new OrderPosition(orderpositionDTO.OrderId, orderpositionDTO.ProductId, orderpositionDTO.Quantity);

            _context.OrderPosition.Add(orderposition);
            _context.SaveChanges();
            return(CreatedAtAction("GetPosition", new { id = orderposition.Id }, orderposition));
        }
Ejemplo n.º 16
0
        public static int GetQuantity(this OrderPosition orderPosition)
        {
            var quantity = orderPosition.GraphicPositions
                           .Where(gp => gp.Id == gp.ParenGraphicPositiontId)
                           .Sum(gp => gp.Count);

            return(quantity);
        }
Ejemplo n.º 17
0
        public AccountPosition CreateAccountPosition(int accountId, OrderPosition orderPosition, List <OrderPosition> packagePositions, DbTransaction dbTran)
        {
            var accountPosition = _accountPositionFactory.Create(accountId, orderPosition, packagePositions);

            accountPosition = _repository.SetAccountPosition(accountPosition, isActual: true, dbTran);

            return(accountPosition);
        }
Ejemplo n.º 18
0
        public ActionResult DeleteConfirmed(int id)
        {
            OrderPosition orderPosition = db.OrderPositions.Find(id);

            db.OrderPositions.Remove(orderPosition);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 19
0
        private DateTime GetFirstOutDate(OrderPosition orderPosition)
        {
            var firstOutDate = orderPosition.GraphicPositions
                               .Select(gp => gp.Graphic.OutDate)
                               .Min();

            return(firstOutDate);
        }
Ejemplo n.º 20
0
        private int GetPositionsCount(OrderPosition orderPosition)
        {
            var count = orderPosition.GraphicPositions
                        .Where(gp => gp.Id == gp.ParenGraphicPositiontId)
                        .Sum(gp => gp.Count);

            return(count);
        }
Ejemplo n.º 21
0
        public static float GetClientPrice(this OrderPosition orderPosition)
        {
            var price = orderPosition.Price.Value *
                        (1 + orderPosition.Markup / 100) *
                        (1 + orderPosition.Nds / 100) *
                        (1 - orderPosition.Discount / 100);

            return((float)Math.Round(price, 2));
        }
Ejemplo n.º 22
0
        public static float GetClientNds(this OrderPosition orderPosition)
        {
            var nds = orderPosition.GraphicPositions.Sum(gp => gp.Count) *
                      orderPosition.Price.Value *
                      (1 + orderPosition.Markup / 100) *
                      (orderPosition.Nds / 100) *
                      (1 - orderPosition.Discount / 100);

            return(nds);
        }
Ejemplo n.º 23
0
 private static void CheckResultOrder(Order order, OrderPosition orderPosition,
                                      StoreItem storeItem, Person person, SinglePositionOrder resultOrder)
 {
     Assert.AreEqual(order.Id, resultOrder.Id);
     Assert.AreEqual(person.Address, resultOrder.Address);
     Assert.AreEqual(orderPosition.Amount, resultOrder.Amount);
     Assert.AreEqual(storeItem.Name, resultOrder.Name);
     Assert.AreEqual(order.OrderNumber, resultOrder.OrderNumber);
     Assert.AreEqual(order.Recipient, resultOrder.Recipient);
 }
Ejemplo n.º 24
0
        public async Task <DestinationNode> GetDestination(OrderPosition orderPosition)
        {
            Argument.ThrowIfNull(nameof(orderPosition), orderPosition);
            Argument.ThrowIfNull(nameof(orderPosition.Order), orderPosition.Order);

            // TODO: This is wrong
            return(_destinationNodes.FirstOrDefault(n =>
                                                    n.Location.PostCode == orderPosition.Order.Location.PostCode &&
                                                    n.AcceptedProducts.Any(p => p.Id == orderPosition.Product.Id)));
        }
Ejemplo n.º 25
0
        public override Neighbour RndNeighbour(Solution solution)
        {
            int           rnd = (int)(Util.Rnd * Program.allPositions.Length);
            OrderPosition op  = Program.allPositions[rnd];

            if (op.Active)
            {
                return(new DisableNeighbour(solution, op));
            }
            return(new ActivateNeighbour(solution, op));
        }
Ejemplo n.º 26
0
 public static Position Position(OrderPosition pos)
 {
     var repo = new ProductRepository();
     var result = new Position
                  {
                      Lp = pos.Lp,
                      Count = pos.Count,
                      Product = repo.GetById(pos.ProductId.Id.ToString())
                  };
     return result;
 }
Ejemplo n.º 27
0
        public OrderPosition DeleteOrderPosition(OrderPosition orderPosition)
        {
            OrderPosition dbEntry = context.OrderPositions.FirstOrDefault(p => p.OrderPositionId == orderPosition.OrderPositionId);

            if (dbEntry != null)
            {
                context.OrderPositions.Remove(dbEntry);
                context.SaveChanges();
            }
            return(dbEntry);
        }
Ejemplo n.º 28
0
        public OperationResult AddProductToCart(string userId, int productId, int selectedQuantity)
        {
            Product productToAdd = _productRepository.GetProductById(productId);

            if (selectedQuantity > productToAdd.Quantity)
            {
                return(OperationResult.Error("Error! Selected quantity is less than state of the warehouse."));
            }

            if (selectedQuantity <= 0)
            {
                return(OperationResult.Error("Error! Selected quantity is too little."));
            }

            var order = GetCartOrRestoreToCart(userId);

            if (order == null)
            {
                order = CreateNewOrder(userId);
            }

            var listOfOrderPositions = _orderRepository.GetOrderById(order.OrderId).OrderPositions;

            var existedProductInOrder = listOfOrderPositions
                                        .Where(o => o.ProductId == productId)
                                        .SingleOrDefault();

            if (existedProductInOrder == null)
            {
                OrderPosition orderPosition = new OrderPosition
                {
                    NameOfProduct = productToAdd.Name,
                    Price         = productToAdd.Price,
                    Quantity      = selectedQuantity,
                    TotalPrice    = selectedQuantity * productToAdd.Price,
                    ProductId     = productId,
                    OrderId       = order.OrderId
                };
                _orderRepository.AddOrderPosition(orderPosition);
            }
            else
            {
                existedProductInOrder.Quantity   = existedProductInOrder.Quantity + selectedQuantity;
                existedProductInOrder.TotalPrice = existedProductInOrder.Quantity * existedProductInOrder.Price;
            }

            var product = _productRepository.GetProductById(productId);

            product.Quantity = product.Quantity - selectedQuantity;
            _productRepository.UpdateProduct(product);
            _orderRepository.Submit();

            return(OperationResult.Success());
        }
Ejemplo n.º 29
0
        public async Task <ActionResult> Order()
        {
            var userId = User.Identity.GetUserId();
            var user   = await _repository.User.Find(userId);


            if (user.BasketItems.Count == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var order = new Order
            {
                // Customer = user.Customer,
                CustomerId = 1,
                OrderDate  = DateTime.Now,
                Discount   = 0
            };

            _repository.Order.Add(order);

            await _repository.Commit();


            var position = 1;

            foreach (var basketItem in user.BasketItems)
            {
                var orderPosition = new OrderPosition
                {
                    Position = position,
                    Order    = order,
                    Amount   = basketItem.Amount,
                    Product  = basketItem.Product,
                    Price    = basketItem.Product.Price,
                    Discount = 0
                };

                _repository.OrderPosition.Add(orderPosition);

                position++;
            }

            var basketItems = user.BasketItems.ToList();

            for (int i = basketItems.Count - 1; i >= 0; i--)
            {
                _repository.BasketItem.Remove(basketItems[i]);
            }

            await _repository.Commit();

            return(RedirectToAction("Details", "Orders", new { id = order.OrderId }));
        }
Ejemplo n.º 30
0
        public void DeleteFullOrderPosition(OrderPosition orderPosition, DbTransaction dbTran)
        {
            _positionImProcessor.DeletePositionIm(orderPosition.PositionIm, dbTran);

            _rubricProcessor.DeleteRubricPositions(orderPosition.RubricPositions, dbTran);
            _graphicProcessor.DeleteGraphicPositions(orderPosition.GraphicPositions, dbTran);

            var isUnloaded = IsUnloaded(orderPosition);

            _repository.SetOrderPosition(orderPosition, isUnloaded, isActual: false, dbTran);
            _context.Entry(orderPosition).Reload();
        }
Ejemplo n.º 31
0
        public static Position Position(OrderPosition pos)
        {
            var repo   = new ProductRepository();
            var result = new Position
            {
                Lp      = pos.Lp,
                Count   = pos.Count,
                Product = repo.GetById(pos.ProductId.Id.ToString())
            };

            return(result);
        }
Ejemplo n.º 32
0
 public void AddProduct(OrderPosition position)
 {
     var id = position.ProductId.Id.ToString();
     var item = Products.Find(x => x.ProductId == id);
     if (item == null)
     {
         var repo = new ProductRepository();
         var product = repo.GetById(id);
         var productSum = new ProductSum(position.ProductId.Id.ToString(), product.Name, product.Ean, position.Count);
         Products.Add(productSum);
     }
     else
     {
         item.ProductCount += position.Count;
     }
 }
Ejemplo n.º 33
0
        public static List<OrderPosition> CreateOrderPosition()
        {
            var productRepository = new ProductRepository();
            var products = productRepository.GetItemsList().ToList();
            var radProduct = new Random(DateTime.Now.Millisecond);
            var productCount = radProduct.Next(1, 10);
            var result = new List<OrderPosition>();

            for (int i = 0; i <= productCount; i++)
            {

                var j = radProduct.Next(products.Count());
                var item = new OrderPosition(i + 1, products[j].Id.ToString(), radProduct.Next(1, 10));
                result.Add(item);
            }
            return result;
        }
Ejemplo n.º 34
0
 public void CreateData()
 {
     pos1 = new OrderPosition(1, "55ddaa59546c56237464705f", 2);
     pos2 = new OrderPosition(2, "55ddaa59546c56237464705f", 1);
     pos3 = new OrderPosition(3, "55ddaa59546c56237464705f", 3);
 }