コード例 #1
0
ファイル: ShoppingController.cs プロジェクト: nayots/SoftUni
        public IHttpResponse Order(IHttpRequest req)
        {
            if (req.QueryParameters.ContainsKey("id"))
            {
                int id = int.Parse(req.QueryParameters["id"]);

                if (!req.Session.Contains("cart"))
                {
                    req.Session.Add("cart", new ShoppingCart());
                }

                var cart = req.Session.Get <ShoppingCart>("cart");

                var cake = CakeList.GetCakeById(id);

                if (cake != null)
                {
                    cart.Cakes.Add(cake);
                }
            }

            string returnPath = "/search";

            string returnUrl = req.QueryParameters["returnUrl"];

            if (!string.IsNullOrEmpty(returnUrl))
            {
                returnPath = $"{returnPath}?name={returnUrl}";
            }

            return(new RedirectResponse(returnPath));
        }
コード例 #2
0
        public HttpResponse AddPost(string name, string price)
        {
            var addView = new AddView();

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(price))
            {
                addView.ErrorString = "Invalid input!";

                return(new ViewResponse(HttpResponceCode.OK, addView));
            }

            var  priceInput = decimal.Parse(price);
            Cake cake       = null;

            if (!string.IsNullOrWhiteSpace(name) && priceInput >= 0)
            {
                cake = new Cake(name, priceInput);
                CakeList.AddCake(cake);
            }

            if (cake != null)
            {
                return(new ViewResponse(HttpResponceCode.OK, new AddView(cake)));
            }

            return(new ViewResponse(HttpResponceCode.OK, new AddView()));
        }
コード例 #3
0
 public void OnCakeDownload()
 {
     foreach (var cake in _cakeManager.DownlodedCakeList.Cakes)
     {
         CakeList.Add(cake);
     }
 }
コード例 #4
0
        public IHttpResponse Order(IHttpRequest request)
        {
            if (request.QueryParameters.ContainsKey("id"))
            {
                int id = int.Parse(request.QueryParameters["id"]);

                Cake cake = CakeList.GetCakeById(id);
                Cart cart = this.GetCartFromSession(request.Session);

                if (cake != null)
                {
                    cart.Cakes.Add(cake);
                }
            }

            string returnPath = "/search";

            string returnUrl = request.QueryParameters["returnUrl"];

            if (!string.IsNullOrEmpty(returnUrl))
            {
                returnPath = $"{returnPath}?name={returnUrl}";
            }

            return(new RedirectResponse(returnPath));
        }
コード例 #5
0
        //POST => add cake
        public IHttpResponse AddCakePost(string name, decimal price)
        {
            CakeList.Add(new Cake(name, price));

            File.WriteAllText("../../../Application/Resources/database.csv", CakeList.GetCakes());

            return(new RedirectResponse($"/add"));
        }
コード例 #6
0
        public IHttpResponse AddPost(string name, double price)
        {
            name = name.Replace(",", string.Empty).Trim();
            if (!string.IsNullOrEmpty(name) && !string.IsNullOrWhiteSpace(name))
            {
                CakeList.Add(new Cake(name, price));
            }

            return(new RedirectResponse($"/add"));
        }
コード例 #7
0
        public string View()
        {
            //<!--...-->
            var result = File.ReadAllText(@".\Application\Resources\add.html");
            var cakes  = CakeList.AllCakes();

            result = result.Replace("<!--...-->", cakes);

            return(result);
        }
コード例 #8
0
ファイル: AddView.cs プロジェクト: nayots/SoftUni
        public string View()
        {
            string html = File.ReadAllText(@".\Application\Resources\add.html");

            string cakesHtml = CakeList.GetCakesAsHtmlString();

            html = html.Replace(ReplacementSnip, cakesHtml);

            return(html);
        }
コード例 #9
0
        public IHttpResponse AddCakePost(string name, string price)
        {
            if (!string.IsNullOrEmpty(name) || !string.IsNullOrEmpty(price))
            {
                var castPriceToDecimal = decimal.Parse(price);
                var cake = new Cake(name, castPriceToDecimal);
                CakeList.Add(cake);
            }

            return(new RedirectResponse("/add"));
        }
コード例 #10
0
        public async Task <CakeList> Cakes()
        {
            var CakesUri   = ApiPath.Cake.GetAllTypes(_baseUri);
            var dataString = await _client.GetStringAsync(CakesUri);

            var cakeList = new CakeList
            {
                Cake = JsonConvert.DeserializeObject <List <Cake> >(dataString)
            };

            return(cakeList);
        }
コード例 #11
0
        public string View()
        {
            string html = File.ReadAllText(@".\Application\Resources\search.html");

            if (!string.IsNullOrEmpty(this.cakeSearchName) && !string.IsNullOrWhiteSpace(this.cakeSearchName))
            {
                string cakesHtml = CakeList.GetCakesAsHtmlString(this.cakeSearchName);

                html = html.Replace(ReplacementSnip, cakesHtml);
            }

            return(html);
        }
コード例 #12
0
        public HttpResponse SearchPost(string name)
        {
            var result     = CakeList.GetCakeByName(name);
            var searchView = new SearchView(result);

            if (string.IsNullOrWhiteSpace(name))
            {
                searchView.ErrorString = "Invalid input!";

                return(new ViewResponse(HttpResponceCode.OK, searchView));
            }

            return(new ViewResponse(HttpResponceCode.OK, searchView));
        }
コード例 #13
0
        public string View()
        {
            string html = File.ReadAllText(@".\Application\Resources\search.html");

            if (!string.IsNullOrEmpty(this.cakeSearchName) && !string.IsNullOrWhiteSpace(this.cakeSearchName))
            {
                string cakesHtml = CakeList.GetCakesAsHtmlString(this.cakeSearchName);

                html = html.Replace(ReplacementSnip, cakesHtml);
            }

            string productsMessage = productCount <= 1 ? $"{productCount} product" : $"{productCount} products";

            html = html.Replace(ProductCountSnip, productsMessage);

            return(html);
        }
コード例 #14
0
        public IHttpResponse Add(Dictionary <string, string> formData)
        {
            if (!formData.ContainsKey("name") || !formData.ContainsKey("price"))
            {
                return(new ViewResponse(HttpStatusCode.Ok, new AddCakeView("error")));
            }

            if (string.IsNullOrWhiteSpace(formData["name"]) || string.IsNullOrWhiteSpace(formData["price"]))
            {
                return(new ViewResponse(HttpStatusCode.Ok, new AddCakeView("error")));
            }

            Cake cake = new Cake(formData["name"], formData["price"]);

            CakeList.SaveCake(cake);

            return(new ViewResponse(HttpStatusCode.Ok, new AddCakeView(cake)));
        }
コード例 #15
0
        public string View()
        {
            //<!--...-->
            var cakes  = string.Empty;
            var result = File.ReadAllText(@".\Application\Resources\search.html");

            if (string.IsNullOrEmpty(criteria))
            {
                cakes = "No records.";
            }
            else
            {
                cakes = CakeList.Search(criteria);
            }

            result = result.Replace("<!--...-->", cakes);

            return(result);
        }
コード例 #16
0
        public IHttpResponse Search(IHttpRequest req)
        {
            Dictionary <string, string> queryPar = req.QueryParameters;
            IHttpSession session = req.Session;

            int productsCount = this.GetProductsCount(session);

            if (!queryPar.ContainsKey("name"))
            {
                return(new ViewResponse(HttpStatusCode.Ok, new SearchCakeView(productsCount)));
            }

            if (!string.IsNullOrWhiteSpace(queryPar["name"]))
            {
                return(new ViewResponse(HttpStatusCode.Ok, new SearchCakeView(productsCount, CakeList.SearchCakes(queryPar["name"]), queryPar["name"])));
            }

            return(new ViewResponse(HttpStatusCode.Ok, new SearchCakeView(productsCount, "error")));
        }
コード例 #17
0
 public void AddCake(string flavour, int size, int layers)
 {
     //add custom cake to list
     CakeList.Add(new CustomCake(flavour, size, layers));
 }
コード例 #18
0
 public void AddCake(string name)
 {
     CakeList.Add(new SpecialCake(name));
 }
コード例 #19
0
 public void ClearCakeList()
 {
     CakeList.Clear();
 }