Example #1
0
        public void ValidateAndSetReadiness(Order order, bool isReady)
        {
            if (order.IsClosed == isReady)
            {
                return;
            }

            if (isReady)
            {
                order.ValidateAndThrow <OrderValidator, Order>("Close", _db);

                var    dbSettingManager = new DbSettingManager(_db);
                double percent;
                if (order.IsNight)
                {
                    percent = dbSettingManager.WorkerNightPercent;
                }
                else
                {
                    percent = dbSettingManager.WorkerDayPercent;
                }

                var    orderItems = GetOrderItems(order);
                double workerPay  = 0;
                if (dbSettingManager.WorkerPayWithDiscount)
                {
                    workerPay = orderItems.Sum(p => p.Quantity * p.LastPrice);
                }
                else
                {
                    workerPay = orderItems.Sum(p => p.Quantity * p.Price);
                }

                workerPay = Math.Round(workerPay * percent, 2);

                _db.Orders
                .Where(p => p.ID == order.ID)
                .Set(p => p.CloseTime, p => DateTime.Now)
                .Set(p => p.WorkerPay, p => workerPay)
                .Update();
            }
            else
            {
                _db.Orders
                .Where(p => p.ID == order.ID)
                .Set(p => p.CloseTime, p => null)
                .Set(p => p.WorkerPay, p => null)
                .Update();
            }
        }
Example #2
0
        public void SetReadiness(IEnumerable <Order> orders, bool isReady)
        {
            if (isReady)
            {
                var    dbSettingManager = new DbSettingManager(_db);
                double percent;
                foreach (var order in orders)
                {
                    if (order.IsClosed == isReady)
                    {
                        continue;
                    }

                    if (order.Validate <OrderValidator, Order>("Close", _db).IsValid)
                    {
                        if (order.IsNight)
                        {
                            percent = dbSettingManager.WorkerNightPercent;
                        }
                        else
                        {
                            percent = dbSettingManager.WorkerDayPercent;
                        }

                        var    orderItems = GetOrderItems(order);
                        double workerPay  = 0;
                        if (dbSettingManager.WorkerPayWithDiscount)
                        {
                            workerPay = orderItems.Sum(p => p.Quantity * p.LastPrice);
                        }
                        else
                        {
                            workerPay = orderItems.Sum(p => p.Quantity * p.Price);
                        }

                        workerPay = Math.Round(workerPay * percent, 2);

                        _db.Orders
                        .Where(p => p.ID == order.ID)
                        .Set(p => p.CloseTime, p => DateTime.Now)
                        .Set(p => p.WorkerPay, p => workerPay)
                        .Update();
                    }
                }
            }
            else
            {
                foreach (var order in orders)
                {
                    if (order.IsClosed == isReady)
                    {
                        continue;
                    }

                    _db.Orders
                    .Where(p => p.ID == order.ID)
                    .Set(p => p.CloseTime, p => null)
                    .Set(p => p.WorkerPay, p => null)
                    .Update();
                }
            }
        }