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)); }
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())); }
public void OnCakeDownload() { foreach (var cake in _cakeManager.DownlodedCakeList.Cakes) { CakeList.Add(cake); } }
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)); }
//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")); }
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")); }
public string View() { //<!--...--> var result = File.ReadAllText(@".\Application\Resources\add.html"); var cakes = CakeList.AllCakes(); result = result.Replace("<!--...-->", cakes); return(result); }
public string View() { string html = File.ReadAllText(@".\Application\Resources\add.html"); string cakesHtml = CakeList.GetCakesAsHtmlString(); html = html.Replace(ReplacementSnip, cakesHtml); return(html); }
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")); }
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); }
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); }
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)); }
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); }
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))); }
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); }
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"))); }
public void AddCake(string flavour, int size, int layers) { //add custom cake to list CakeList.Add(new CustomCake(flavour, size, layers)); }
public void AddCake(string name) { CakeList.Add(new SpecialCake(name)); }
public void ClearCakeList() { CakeList.Clear(); }