Пример #1
0
        public void GetBirdObservationReport()
        {
            List <string> observationList = BirdWatchLogFile.ReadObservations();

            JavaScriptSerializer jsonStream = new JavaScriptSerializer();

            Context.Response.Write(jsonStream.Serialize(observationList));
        }
Пример #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);
        }
Пример #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);
        }