Example #1
0
        public IActionResult OnGet(int?id = 0)
        {
            var model = new WebUI2.Model.Goods();

            if (id > 0)
            {
                model = _razorPageDbContex.Goods.FirstOrDefault(x => x.Id == id);
            }
            InputGoods = model;
            return(Page());
        }
Example #2
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var goods = new WebUI2.Model.Goods {
                Name = InputGoods.Name, Price = InputGoods.Price
            };

            _razorPageDbContex.Goods.Add(goods);
            _razorPageDbContex.SaveChanges();
            return(RedirectToPage("/Goods/Index"));
        }