示例#1
0
        public IActionResult Order(OrderModel model)
        {
            //Validation for int inputs in form
            if (model.Length >= 1 && model.Length <= 100 || model.Width >= 1 && model.Width <= 100)
            {
                model.Count(); //Calculates kvm and total price
            }
            else
            {
                return(View());
            }

            //Validation for inputs in form for model
            if (ModelState.IsValid)
            {
                //Open JSON file, add new model
                var Json    = System.IO.File.ReadAllText("orders.json");
                var JsonObj = JsonConvert.DeserializeObject <List <OrderModel> >(Json);
                JsonObj.Add(model);

                //Close JSON file
                System.IO.File.WriteAllText("orders.json", JsonConvert.SerializeObject(JsonObj, Formatting.Indented));

                //Start session
                string s = JsonConvert.SerializeObject(model);
                HttpContext.Session.SetString("order-session", s);

                return(RedirectToAction("Confirmation", "Floor"));
            }

            return(View());
        }