Exemplo n.º 1
0
        public void DeleteUnit(long hostingUnitKey)
        {
            HostingUnit certianUnit = FindUnitByKey(hostingUnitKey);
            var         allOrders   = GetAllOrders();

            foreach (var item in GetAllOrders())
            {
                if ((item.Status == OrderStatus.MailSend ||
                     item.Status == OrderStatus.NotYetHandle) &&
                    item.HostingUnitKey == hostingUnitKey)
                {
                    throw new ArgumentException("can't delete, their is still open order");
                }
            }
            try
            {
                dal.DeleteUnit(certianUnit);
            }
            catch (Exception exc) //catch 2 tipes of exceptions.
            {
                if (exc is KeyNotFoundException)
                {
                    throw exc;
                }
                if (exc is ArgumentNullException)
                {
                    throw new ArgumentNullException("The key exists, /n Unable to find content by key");
                }
                else
                {
                    throw exc;
                }
            }
        }