예제 #1
0
        private void ValidateOrder(Order order, bool shouldCheckPostamatStatus = false)
        {
            if (order.Price < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(order.Price));
            }

            if (order.Products.Length > MaxNumberOfProducts)
            {
                throw new ArgumentOutOfRangeException(nameof(order.Products));
            }

            var postamat = _postamatRepository.GetOrDefault(order.PostamatId);

            if (postamat == null)
            {
                throw new ArgumentOutOfRangeException(nameof(order.PostamatId));
            }

            if (shouldCheckPostamatStatus && !postamat.IsWorking)
            {
                throw new ArgumentException("Postamat is not working currently");
            }

            if (!Regex.IsMatch(order.CustomerPhoneNumber, TelephoneNumberPattern))
            {
                throw new FormatException("Wrong telephone number format");
            }
        }
예제 #2
0
        public ActionResult <Postamat> Get(int postamatId)
        {
            var postamat = _postamatRepository.GetOrDefault(postamatId);

            if (postamat == null)
            {
                return(NotFound());
            }

            return(postamat);
        }