Ejemplo n.º 1
0
        public bool AddProduct(ProductEntity pe)
        {
            if (string.IsNullOrEmpty(pe.ProductName) || string.IsNullOrWhiteSpace(pe.ProductName))
            {
                throw new Exception("ProductName cannot be Blank or empty");
            }
            if (string.IsNullOrEmpty(pe.Description) || string.IsNullOrWhiteSpace(pe.Description))
            {
                throw new Exception("Description cannot be Blank or empty");
            }

            if (pe.Price <= 0)
            {
                throw new Exception("Price Cannot be zero or negative");
            }
            if (pe.Discount < 0)
            {
                throw new Exception("Discount cannot be negative");
            }

            if (string.IsNullOrEmpty(pe.Image) || string.IsNullOrWhiteSpace(pe.Image))
            {
                throw new Exception("Image Path cannot be blank");
            }
            Regex filepath = new Regex(@"^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+\.(jpeg|gif|png)$");

            if (filepath.IsMatch(pe.Image))
            {
            }
            else
            {
                throw new Exception("Valid FilePath should be given and extension should be .jpeg,gif or png");
            }


            return(dal.AddProduct(pe));
        }