Exemplo n.º 1
0
        public void parse(string request)
        {
            string[] get = request.Split(' ');
            if (!validateGet(get))
            {
                htmlBuilder.createDump();
                return;
            }
            string[] url = get[2].Split('/');
            if (!validateUrl(url))
            {
                htmlBuilder.createDump();
                return;
            }
            string subsectionType = "";
            string custId         = get[1];
            int    bookIdInt      = 0;
            int    custIdInt      = 0;

            subsectionType = getSubsectionType(url, out string bookId);
            if (!validateSubsectionType(subsectionType, url))
            {
                htmlBuilder.createDump();
                return;
            }

            if (!(int.TryParse(bookId, out bookIdInt) && int.TryParse(custId, out custIdInt)))
            {
                htmlBuilder.createDump();
                return;
            }
            Customer customer = store.GetCustomer(custIdInt);
            Book     book     = store.GetBook(bookIdInt);

            if (customer == null || (book == null && bookIdInt != -5769765))
            {
                htmlBuilder.createDump();
                return;
            }

            switch (subsectionType)
            {
            case "Add":
                if (!addItemToCart(store, bookIdInt, store.GetCustomer(custIdInt).ShoppingCart))
                {
                    htmlBuilder.createDump();
                    return;
                }
                break;

            case "Remove":
                if (!removeItemFromCart(store, bookIdInt, store.GetCustomer(custIdInt).ShoppingCart))
                {
                    htmlBuilder.createDump();
                    return;
                }
                break;

            case "":
                htmlBuilder.createDump();
                return;
            }

            htmlBuilder.createWebPage(subsectionType, bookIdInt, int.Parse(custId), store);
        }