Exemplo n.º 1
0
        public void GetBirdWatchData()
        {
            List <BirdWatchItem> birdList = BirdWatchDataFile.Read();

            JavaScriptSerializer jsonString = new JavaScriptSerializer();

            Context.Response.Write(jsonString.Serialize(birdList));
        }
Exemplo n.º 2
0
        public void IncrementBirdObservations(string birdName)
        {
            List <BirdWatchItem> birdList = BirdWatchDataFile.Read();

            for (int i = 0; i < birdList.Count; i++)
            {
                if (birdList[i].BirdName == birdName)
                {
                    birdList[i].IncrementBirdObservations();
                    break;
                }
            }

            BirdWatchLogFile.Write(birdName, birdList);
            BirdWatchDataFile.Write(birdList);
        }
Exemplo n.º 3
0
        public string AddNewBirdItem(string birdName)
        {
            List <BirdWatchItem> birdList   = BirdWatchDataFile.Read();
            JavaScriptSerializer jsonStream = new JavaScriptSerializer();

            // Validate
            if (string.IsNullOrEmpty(birdName) || !Regex.IsMatch(birdName, @"^[a-öA-Ö]+$"))
            {
                return("Virhe: virheellinen linnun nimi");
            }

            for (int i = 0; i < birdList.Count; i++)
            {
                if (birdList[i].BirdName == birdName)
                {
                    return("Virhe: yritit lisätä duplikaattia");
                }
            }

            birdList.Add(new BirdWatchItem(birdName, 0));
            BirdWatchLogFile.Write(birdName);
            BirdWatchDataFile.Write(birdList);
            return(string.Empty);
        }