Exemple #1
0
        public Bird updateBirdCount(Int32 birdID)
        {
            Bird tmp;

            try
            {
                using (var ctx = new SightingContext())
                {
                    tmp = ctx.birds.SingleOrDefault(b => b.BirdID == birdID);
                    if (tmp != null)
                    {
                        tmp.Count = tmp.Count + 1;
                        ctx.SaveChanges();
                    }
                    else
                    {
                        log.Error("Could not find bird : " + birdID);
                    }
                }
            } catch (Exception ex) {
                log.Error("Error when adding sighting : {birdID}", ex);
                throw new ApplicationException("Error when adding sighting : {birdID}", ex);
            }

            return(tmp);
        }
Exemple #2
0
        public bool addBird(string Name)
        {
            bool retval = false;

            try
            {
                using (var ctx = new SightingContext())
                {
                    var stud = new Bird()
                    {
                        Name = Name, Count = 0
                    };
                    ctx.birds.Add(stud);
                    ctx.SaveChanges();
                    retval = true;
                }
            } catch (Exception ex) {
                log.Error("Error when adding bird : {Name}", ex);
                throw new ApplicationException("Error when adding bird : {Name}", ex);
            }
            return(retval);
        }
Exemple #3
0
        public bool addSighting(Int32 birdID)
        {
            bool retval = false;

            try
            {
                using (var ctx = new SightingContext())
                {
                    var stud = new Sighting()
                    {
                        BirdID = birdID, SightingDate = DateTime.Now
                    };
                    ctx.sightings.Add(stud);
                    ctx.SaveChanges();

                    retval = true;
                }
            } catch (Exception ex) {
                log.Error("Error when adding sighting : {birdID}", ex);
                throw new ApplicationException("Error when adding sighting : {birdID}", ex);
            }

            return(retval);
        }