コード例 #1
0
        public IActionResult Index(Reservation reservationModel)
        {
            List <Reservation> reservation = new List <Reservation>();
            JSONReadWrite      readWrite   = new JSONReadWrite();

            reservation = JsonConvert.DeserializeObject <List <Reservation> >(readWrite.Read("people.json", "data"));

            Reservation person = reservation.FirstOrDefault(x => x.Id == reservationModel.Id);

            if (person == null)
            {
                reservation.Add(reservationModel);
            }
            else
            {
                int index = reservation.FindIndex(x => x.Id == reservationModel.Id);
                reservation[index] = reservationModel;
            }

            string jSONString = JsonConvert.SerializeObject(reservation);

            readWrite.Write("people.json", "data", jSONString);

            return(Ok());
        }
コード例 #2
0
        // public IActionResult Post(int id,string name,string surname, List<string> shoes,bool hungry,int age)
        public IActionResult PostPeople(Person personModel)
        {
            List <Person> people    = new List <Person>();
            JSONReadWrite readWrite = new JSONReadWrite();

            people = JsonConvert.DeserializeObject <List <Person> >(readWrite.Read("people.json", "data"));

            // Person personModel = new Person { Id = id, Name = name, Surname = surname, Shoes = shoes, Hungry = hungry, Age = age };
            Person person = people.FirstOrDefault(x => x.Id == personModel.Id);

            if (person == null)
            {
                people.Add(personModel);
            }
            else
            {
                int index = people.FindIndex(x => x.Id == personModel.Id);
                people[index] = personModel;
            }

            string jSONString = JsonConvert.SerializeObject(people);

            readWrite.Write("people.json", "data", jSONString);

            return(Ok());
        }
コード例 #3
0
        protected void EditProductButtonClick(object sender, EventArgs e)
        {
            int id = int.TryParse(ProductIdField.Value, out int result) ? result : 0;

            JSONReadWrite  readWrite  = new JSONReadWrite();
            string         jsonString = readWrite.Read("products.json", "Data");
            List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

            Product product = products.Where(p => p.ProductId == id).FirstOrDefault();

            if (product == null)
            {
                Response.Redirect("/Views/Products/ProductsPage.aspx");
            }

            product.Title        = ProductNameTextBox.Text;
            product.Description  = ProductDescriptionTextBox.Text;
            product.Category     = products.Select(s => s.Category).Where(c => c.CategoryName == CategoryDropDownList.SelectedValue).FirstOrDefault();
            product.Supplier     = products.Select(s => s.Supplier).Where(s => s.SupplierName == SupplierDropDownList.SelectedValue).FirstOrDefault();
            product.Manufacturer = products.Select(s => s.Manufacturer).Where(m => m.ManufacturerName == ManufacturerDropDownList.SelectedValue).FirstOrDefault();
            product.Price        = decimal.TryParse(PriceTextBox.Text, out decimal priceResult) ? priceResult : 0;

            int index = products.FindIndex(f => f.ProductId == id);

            products[index] = product;

            string jsonWriteString = JsonConvert.SerializeObject(products);

            readWrite.Write("products.json", "Data", jsonWriteString);

            Response.Redirect("/Views/Products/ProductsPage.aspx");
        }
コード例 #4
0
        public IActionResult GetBestDay()
        {
            JSONReadWrite readWrite = new JSONReadWrite();

            string[]      files    = new string[] { "en.1.json", "en.2.json", "en.3.json" };
            List <League> leagues  = new List <League>();
            List <Match>  matches  = new List <Match>();
            List <Match>  bestDays = new List <Match>();

            for (int l = 0; l < 3; l++)
            {
                leagues = JsonConvert.DeserializeObject <List <League> >(readWrite.Read(files[l], "data"));

                for (int j = 0; j < 1; j++)
                {
                    for (int i = 0; i < leagues[j].Matches.Count; i++)
                    {
                        matches.Add(new Match {
                            leagueName = leagues[j].Name, Round = leagues[j].Matches[i].Round, Date = leagues[j].Matches[i].Date, Team1 = leagues[j].Matches[i].Team1, Team2 = leagues[j].Matches[i].Team2, Score = leagues[j].Matches[i].Score
                        });
                    }
                }
                bestDays.AddRange(matches.Where(m => m.Score.Ft[0] + m.Score.Ft[1] == matches.Max(m => m.Score.Ft[0] + m.Score.Ft[1])));
                matches.Clear();
            }

            return(View(bestDays));
        }
コード例 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            JSONReadWrite  readWrite  = new JSONReadWrite();
            string         jsonString = readWrite.Read("products.json", "Data");
            List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

            var categories    = products.GroupBy(g => g.Category.CategoryId).Select(s => s.FirstOrDefault().Category).ToList();
            var suppliers     = products.GroupBy(g => g.Supplier.SupplierId).Select(s => s.FirstOrDefault().Supplier).ToList();
            var manufacturers = products.GroupBy(g => g.Manufacturer.ManufacturerId).Select(s => s.FirstOrDefault().Manufacturer).ToList();

            CategoryDropDownList.DataSource    = categories;
            CategoryDropDownList.DataTextField = "CategoryName";
            CategoryDropDownList.ID            = "CategoryId";
            CategoryDropDownList.DataBind();

            SupplierDropDownList.DataSource    = suppliers;
            SupplierDropDownList.DataTextField = "SupplierName";
            SupplierDropDownList.ID            = "SupplierId";
            SupplierDropDownList.DataBind();

            ManufacturerDropDownList.DataSource    = manufacturers;
            ManufacturerDropDownList.DataTextField = "ManufacturerName";
            ManufacturerDropDownList.ID            = "ManufacturerId";
            ManufacturerDropDownList.DataBind();
        }
コード例 #6
0
        public IActionResult Index()
        {
            List <HomeModel> employee  = new List <HomeModel>();
            JSONReadWrite    readWrite = new JSONReadWrite();

            employee = JsonConvert.DeserializeObject <List <HomeModel> >(readWrite.Read("employee.json", "data"));
            return(View(employee));
        }
コード例 #7
0
        public IActionResult People()
        {
            List <Person> people    = new List <Person>();
            JSONReadWrite readWrite = new JSONReadWrite();

            people = JsonConvert.DeserializeObject <List <Person> >(readWrite.Read("People.json", "data"));
            return(Ok(people));
        }
コード例 #8
0
        public List <ProductViewModel> GetProductsFromJSON()
        {
            JSONReadWrite  readWrite  = new JSONReadWrite();
            string         jsonString = readWrite.Read("products.json", "Data");
            List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

            return(ProductViewModel.GetProductsViewModel(products));
        }
コード例 #9
0
ファイル: MenuController.cs プロジェクト: vipyadav/WebAPIDemo
        public IActionResult Menus()
        {
            var           menus     = VipDataContext.Menus;
            List <Menu>   people    = new List <Menu>();
            JSONReadWrite readWrite = new JSONReadWrite();

            menus = JsonConvert.DeserializeObject <List <Menu> >(readWrite.Read("CafeData.json", "data"));
            return(Ok(menus));
        }
コード例 #10
0
        public IActionResult Delete(int id)
        {
            List <HomeModel> employee  = new List <HomeModel>();
            JSONReadWrite    readWrite = new JSONReadWrite();

            employee = JsonConvert.DeserializeObject <List <HomeModel> >(readWrite.Read("employee.json", "data"));
            int index = employee.FindIndex(x => x.Id == id);

            employee.RemoveAt(index);
            string jSONString = JsonConvert.SerializeObject(employee);

            readWrite.Write("employee.json", "data", jSONString);
            return(RedirectToAction("Index", "Home"));
        }
コード例 #11
0
        public IActionResult GetPeople(int id)
        {
            List <Person> people    = new List <Person>();
            JSONReadWrite readWrite = new JSONReadWrite();

            people = JsonConvert.DeserializeObject <List <Person> >(readWrite.Read("People.json", "data"));
            var person = people.FirstOrDefault(m => m.Id == id);

            if (person == null)
            {
                return(NotFound());
            }

            return(Ok(person));
        }
コード例 #12
0
        public IActionResult Delete(int id)
        {
            List <Reservation> reservation = new List <Reservation>();
            JSONReadWrite      readWrite   = new JSONReadWrite();

            reservation = JsonConvert.DeserializeObject <List <Reservation> >(readWrite.Read("people.json", "data"));

            int index = reservation.FindIndex(x => x.Id == id);

            reservation.RemoveAt(index);

            string jSONString = JsonConvert.SerializeObject(reservation);

            readWrite.Write("people.json", "data", jSONString);

            return(RedirectToAction("index", "Person"));
        }
コード例 #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = int.TryParse(Request.QueryString["Id"], out int result) ? result : 0;

                JSONReadWrite  readWrite  = new JSONReadWrite();
                string         jsonString = readWrite.Read("products.json", "Data");
                List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

                Product product = products.Where(p => p.ProductId == id).FirstOrDefault();

                if (product == null)
                {
                    Response.Redirect("/Views/Products/ProductsPage.aspx");
                }

                ProductIdField.Value           = product.ProductId.ToString();
                ProductNameTextBox.Text        = product.Title;
                ProductDescriptionTextBox.Text = product.Description;
                PriceTextBox.Text = product.Price.ToString();

                var categories    = products.GroupBy(g => g.Category.CategoryId).Select(s => s.FirstOrDefault().Category).ToList();
                var suppliers     = products.GroupBy(g => g.Supplier.SupplierId).Select(s => s.FirstOrDefault().Supplier).ToList();
                var manufacturers = products.GroupBy(g => g.Manufacturer.ManufacturerId).Select(s => s.FirstOrDefault().Manufacturer).ToList();

                CategoryDropDownList.DataSource    = categories;
                CategoryDropDownList.SelectedValue = product.Category.CategoryName;
                CategoryDropDownList.DataTextField = "CategoryName";
                CategoryDropDownList.DataBind();

                SupplierDropDownList.Items.Add(" ");
                SupplierDropDownList.DataSource    = suppliers;
                SupplierDropDownList.SelectedValue = product.Supplier.SupplierName;
                SupplierDropDownList.DataTextField = "SupplierName";
                SupplierDropDownList.DataBind();

                ManufacturerDropDownList.DataSource    = manufacturers;
                ManufacturerDropDownList.SelectedValue = product.Manufacturer.ManufacturerName;
                ManufacturerDropDownList.DataTextField = "ManufacturerName";
                ManufacturerDropDownList.DataBind();
            }
        }
コード例 #14
0
        public IActionResult Add(HomeModel personModel)
        {
            List <HomeModel> employee  = new List <HomeModel>();
            JSONReadWrite    readWrite = new JSONReadWrite();

            employee = JsonConvert.DeserializeObject <List <HomeModel> >(readWrite.Read("employee.json", "data"));
            HomeModel person = employee.FirstOrDefault(x => x.Id == personModel.Id);

            if (person == null)
            {
                employee.Add(personModel);
            }
            else
            {
                ViewData["Message"] = "Modified data of employee.";
                int index = employee.FindIndex(x => x.Id == personModel.Id);
                employee[index] = personModel;
            }
            string jSONString = JsonConvert.SerializeObject(employee);

            readWrite.Write("employee.json", "data", jSONString);
            return(RedirectToAction("Index", "Home"));
        }
コード例 #15
0
        protected void AddProductButtonClick(object sender, EventArgs e)
        {
            JSONReadWrite  readWrite  = new JSONReadWrite();
            string         jsonString = readWrite.Read("products.json", "Data");
            List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

            Product product = new Product();

            product.ProductId    = products.Count + 1;
            product.Title        = ProductNameTextBox.Text;
            product.Description  = ProductDescriptionTextBox.Text;
            product.Category     = products.Select(s => s.Category).Where(c => c.CategoryName == CategoryDropDownList.SelectedValue).FirstOrDefault();
            product.Supplier     = products.Select(s => s.Supplier).Where(s => s.SupplierName == SupplierDropDownList.SelectedValue).FirstOrDefault();
            product.Manufacturer = products.Select(s => s.Manufacturer).Where(m => m.ManufacturerName == ManufacturerDropDownList.SelectedValue).FirstOrDefault();
            product.Price        = decimal.TryParse(PriceTextBox.Text, out decimal result) ? result : 0;

            products.Add(product);

            string jsonWriteString = JsonConvert.SerializeObject(products);

            readWrite.Write("products.json", "Data", jsonWriteString);

            Response.Redirect("/Views/Products/ProductsPage.aspx");
        }
        //public bool isValidUser { get; set; }

        public AccountController()
        {
            json  = new JSONReadWrite();
            users = new List <User>();
            users = JsonConvert.DeserializeObject <List <User> >(json.Read("users.json", "./"));
        }
コード例 #17
0
        public IActionResult GetBestAttackTeam()
        {
            JSONReadWrite readWrite = new JSONReadWrite();

            string[]      files     = new string[] { "en.1.json", "en.2.json", "en.3.json" };
            List <League> leagues   = new List <League>();
            List <Match>  matches   = new List <Match>();
            List <Team>   teams     = new List <Team>();
            List <Team>   bestTeams = new List <Team>();

            for (int l = 0; l < 3; l++)
            {
                leagues = JsonConvert.DeserializeObject <List <League> >(readWrite.Read(files[l], "data"));

                for (int j = 0; j < 1; j++)
                {
                    for (int i = 0; i < leagues[j].Matches.Count; i++)
                    {
                        matches.Add(leagues[j].Matches[i]);
                    }
                }

                foreach (var item in matches)
                {
                    var currentTeam = teams.Find(t => t.Name == item.Team1);
                    if (currentTeam != null)
                    {
                        currentTeam.Goals       += item.Score.Ft[0];
                        currentTeam.MissedGoals += item.Score.Ft[1];
                        currentTeam.LeagueName   = leagues[0].Name;
                    }
                    else
                    {
                        var newTeam = new Team();
                        newTeam.Name        = item.Team1;
                        newTeam.Goals       = item.Score.Ft[0];
                        newTeam.MissedGoals = item.Score.Ft[1];
                        newTeam.LeagueName  = leagues[0].Name;
                        teams.Add(newTeam);
                    }
                }
                foreach (var item in matches)
                {
                    var currentTeam = teams.Find(t => t.Name == item.Team2);
                    if (currentTeam != null)
                    {
                        currentTeam.Goals       += item.Score.Ft[0];
                        currentTeam.MissedGoals += item.Score.Ft[1];
                        currentTeam.LeagueName   = leagues[0].Name;
                    }
                    else
                    {
                        var newTeam = new Team();
                        newTeam.Name        = item.Team1;
                        newTeam.Goals       = item.Score.Ft[1];
                        newTeam.MissedGoals = item.Score.Ft[0];
                        newTeam.LeagueName  = leagues[0].Name;
                        teams.Add(newTeam);
                    }
                }

                bestTeams.AddRange(teams.Where(t => t.Goals == teams.Max(t => t.Goals))
                                   .Select(t => new Team {
                    Name = t.Name, LeagueName = t.LeagueName
                }));
                teams.Clear();
                matches.Clear();
            }
            return(View("GetBestTeam", bestTeams));
        }