示例#1
0
        public IActionResult ProductList()
        {
            var webClient = new RestSharpWebClient();
            var model     = webClient.GetProducts();

            return(View(model));
        }
示例#2
0
        public ActionResult Edit(string id, IFormCollection collection)
        {
            try
            {
                var product = new ProductViewModel
                {
                    ProductId           = new Guid(collection["ProductId"]),
                    ProductName         = collection["ProductName"],
                    ProductDescription  = collection["ProductDescription"],
                    ProductImage        = collection["ProductImage"],
                    ProductPrice        = Convert.ToDecimal(collection["ProductPrice"]),
                    CategoryId          = new Guid(collection["CategoryId"]),
                    CategoryName        = collection["CategoryName"],
                    CategoryDescription = collection["CategoryDescription"]
                };

                var webClient      = new RestSharpWebClient();
                var producresponse = webClient.UpdateProduct(id, product);
                if (producresponse)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                throw new Exception();
            }
            catch
            {
                return(View());
            }
        }
示例#3
0
        public IActionResult Create(IFormCollection collection)
        {
            try
            {
                var product = new ProductViewModel
                {
                    ProductId           = Guid.NewGuid(),
                    ProductName         = collection["ProductName"],
                    ProductDescription  = collection["ProductDescription"],
                    ProductImage        = collection["ProductImage"],
                    ProductPrice        = Convert.ToDecimal(collection["ProductPrice"]),
                    CategoryId          = new Guid("77DD5B53-8439-49D5-9CBC-DC5314D6F190"),
                    CategoryName        = collection["CategoryName"],
                    CategoryDescription = collection["CategoryDescription"]
                };

                var webClient      = new RestSharpWebClient();
                var producresponse = webClient.AddProduct(product);
                if (producresponse)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                throw new Exception();
            }
            catch
            {
                return(View());
            }
        }
示例#4
0
        public ActionResult Edit(string id)
        {
            var webClient = new RestSharpWebClient();
            var product   = webClient.GetProductDetails(id);

            return(View(product));
        }
示例#5
0
        public ActionResult Index()
        {
            var webClient = new RestSharpWebClient();
            var products  = webClient.GetProducts();

            return(View("ProductList", products));
        }