/// <summary>
 /// Get status object by filter criteria
 /// </summary>
 /// <param name="statusSearchDTO">statusSearchDTO object</param>
 /// <returns>List of status objects</returns>
 public Status GetStatusByName(StatusSearchDTO statusSearchDTO)
 {
     return GetAllStatuses().Where(s => s.Name == statusSearchDTO.Name).FirstOrDefault<Status>();
 }
 /// <summary>
 /// Get status object by filter criteria
 /// </summary>
 /// <param name="statusSearchDTO">statusSearchDTO object</param>
 /// <returns>List of status objects</returns>
 public List<Status> GetStatusByCriteria(StatusSearchDTO statusSearchDTO)
 {
     return GetAllStatuses().Where(s => s.Name == statusSearchDTO.Name).ToList<Status>();
 }
        /// <summary>
        /// Get status object by filter criteria
        /// </summary>
        /// <param name="statusSearchDTO">statusSearchDTO object</param>
        /// <returns>List of status objects</returns>
        public List<Status> GetStatusByCriteria(StatusSearchDTO statusSearchDTO)
        {
            List<Status> temp = requisitionDAO.GetStatusByCriteria(statusSearchDTO);

            if (temp != null)
                return temp;

            ErrorMessage("Result not found");
            return null;
        }
        /// <summary>
        /// Get status object by filter criteria
        /// </summary>
        /// <param name="statusSearchDTO">statusSearchDTO object</param>
        /// <returns>List of status objects</returns>
        public Status GetStatusByName(StatusSearchDTO statusSearchDTO)
        {
            var temp = requisitionDAO.GetStatusByName(statusSearchDTO);

            if (temp != null)
                return temp;

            ErrorMessage("Result not found");
            return null;
        }
        /// <summary>
        /// Create a new requisition and persist with database
        /// </summary>
        /// <param name="requisition">requisition object</param>
        public Requisition CreateRequisition(Requisition requisition)
        {
            try
            {
                bool isTestOK = false;
                StatusSearchDTO sdto = new StatusSearchDTO() { Name = "Pending" };
                Status status = requisitionDAO.GetStatusByName(sdto);
                requisition.StatusID = status.StatusID;

                if (ValidateRequisition(requisition, RequisitionMethod.Create))
                {
                    if (requisition.RequisitionItems.Count > 0 || requisition.SpecialRequisitionItems.Count > 0)
                    {
                        foreach (RequisitionItem requisitionItem in requisition.RequisitionItems)
                        {
                            isTestOK = ValidateRequisitionItem(requisitionItem, RequisitionMethod.Create);
                            if (!isTestOK)
                            {
                                break;
                            }
                        }
                        foreach (SpecialRequisitionItem specialRequisitionItem in requisition.SpecialRequisitionItems)
                        {
                            isTestOK = ValidateSpecialRequisitionItem(specialRequisitionItem, RequisitionMethod.Create);

                            if (!isTestOK)
                            {
                                break;
                            }
                        }
                    }

                    if (isTestOK)
                    {

                        requisitionDAO.CreateRequisition(requisition);
                        return requisition;
                    }

                    else
                    {
                        ErrorMessage("Create Requisition Failed. Please check the input.");
                    }
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return null;
        }