Exemplo n.º 1
0
        /// <summary>
        /// Retrieve active orders for a given day. Active and assigned OR all active
        /// </summary>
        /// <param name="date">filter for the date</param>
        /// <param name="assignedOnly">filter to only orders with fully assigned jobs</param>
        /// <returns>WorkOrders associated with a given date that are active</returns>
        public IEnumerable <WorkOrder> GetActiveOrders(DateTime date, bool assignedOnly)
        {
            var matching = repo.GetActiveOrders(date);

//                .Where(wo => wo.statusID == WorkOrder.iActive
//                          && wo.dateTimeofWork.Date == date.Date).ToList();

            if (!assignedOnly)
            {
                return(matching);
            }

            var result = new List <WorkOrder>();

            foreach (WorkOrder wo in matching)
            {
                // WO must have at least one WA to be marked active
                if (wo.workAssignments.Count == 0)
                {
                    continue;
                }

                var nullAssignments = 0;

                foreach (var wa in wo.workAssignments)
                {
                    if (wa.workerAssignedID == null)
                    {
                        nullAssignments++;
                    }
                }

                if (nullAssignments > 0)
                {
                    continue;
                }

                result.Add(wo);
            }

            return(result);
        }