Beispiel #1
0
        public List <FishTO> GetAllFish()
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var query = (from fish in db.Fish select fish);

                List <FishTO> fishes = new List <FishTO>();

                foreach (var fsh in query)
                {
                    FishTO fish = new FishTO();
                    fish.id      = fsh.id;
                    fish.name    = fsh.name;
                    fish.species = fsh.species;
                    fish.tripId  = (int)fsh.tripId;
                    fish.weight  = (double)fsh.weight;
                    fish.length  = (double)fsh.length;
                    if (fsh.caughtDate != null)
                    {
                        fish.caughtDate = ((DateTime)fsh.caughtDate).ToString("yyyy-MM-dd HH:mm:ss tt");
                    }

                    fish.girth        = fsh.girth;
                    fish.spot         = fsh.spot;
                    fish.presentation = fsh.presentation;
                    fish.depth        = fsh.depth;
                    fish.clarity      = fsh.clarity;
                    fish.temperature  = fsh.temperature;

                    fishes.Add(fish);
                }

                return(fishes);
            }
        }
Beispiel #2
0
        public List<FishTO> GetAllFish()
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var query = (from fish in db.Fish select fish);

                List<FishTO> fishes = new List<FishTO>();

                foreach (var fsh in query)
                {
                    FishTO fish = new FishTO();
                    fish.id = fsh.id;
                    fish.name = fsh.name;
                    fish.species = fsh.species;
                    fish.tripId = (int)fsh.tripId;
                    fish.weight = (double)fsh.weight;
                    fish.length = (double)fsh.length;
                    if (fsh.caughtDate != null)
                        fish.caughtDate = ((DateTime)fsh.caughtDate).ToString("yyyy-MM-dd HH:mm:ss tt");
                    fishes.Add(fish);
                }

                return fishes;
            }
        }
Beispiel #3
0
        public void Put([FromBody] FishTO fishTO)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var fishDB = (from fish in db.Fish
                              where fish.id == fishTO.id
                              select fish).FirstOrDefault();

                fishDB.name    = fishTO.name;
                fishDB.weight  = fishTO.weight;
                fishDB.notes   = fishTO.notes;
                fishDB.length  = fishTO.length;
                fishDB.tripId  = fishTO.tripId;
                fishDB.species = fishTO.species;

                fishDB.girth        = fishTO.girth;
                fishDB.spot         = fishTO.spot;
                fishDB.presentation = fishTO.presentation;
                fishDB.depth        = fishTO.depth;
                fishDB.clarity      = fishTO.clarity;
                fishDB.temperature  = fishTO.temperature;

                fishDB.caughtDate = parseDateTimeExactFromString(fishTO.caughtDate);
                db.SaveChanges();
            }
        }
Beispiel #4
0
        public List<FishTO> GetAllFishForTripId(int tripId, string token)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var guid = new Guid(token);
                var query = (from fish in db.Fish
                             join trip in db.Trips on fish.tripId.Value equals trip.id
                             join user in db.Users on trip.userId.Value equals user.id
                             where user.token == guid && trip.id == tripId
                             select fish);

                List<FishTO> fishes = new List<FishTO>();

                foreach (var f in query)
                {
                    FishTO fish = new FishTO();
                    fish.id = f.id;
                    fish.tripId = (int)f.tripId;
                    fish.name = f.name;
                    fish.notes = f.notes;
                    fish.weight = (double)f.weight;
                    fish.length = (double)f.length;
                    fish.species = f.species;
                    if (f.caughtDate != null)
                    {
                        fish.caughtDate = ((DateTime)f.caughtDate).ToString("yyyy-MM-dd");
                        fish.caughtTime = ((DateTime)f.caughtDate).TimeOfDay.ToString("HH:mm:ss tt");
                    }
                    fishes.Add(fish);
                }

                return fishes;
            }
        }
Beispiel #5
0
        public string UpdateFish(FishTO fishTO, string token)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var guid   = new Guid(token);
                var fishDB = (from fish in db.Fish
                              where fish.id == fishTO.id
                              select fish).FirstOrDefault();
                if (fishDB == null)
                {
                    return(null);
                }

                db.Fish.Attach(fishDB);

                fishDB.name    = fishTO.name;
                fishDB.species = fishTO.species;
                fishDB.length  = fishTO.length;
                fishDB.weight  = fishTO.weight;
                fishDB.notes   = fishTO.notes;
                string date = fishTO.caughtDate + " " + fishTO.caughtTime;
                fishDB.caughtDate = DateTime.ParseExact(fishTO.caughtDate, "yyyy-MM-dd HH:mm:ss tt", CultureInfo.InvariantCulture);

                db.SaveChanges();
            }
            return(null);
        }
Beispiel #6
0
        public FishTO GetFishForId(int fishId, string token)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var guid   = new Guid(token);
                var fishDB = (from fishLQ in db.Fish
                              where fishLQ.id == fishId
                              select fishLQ).FirstOrDefault();
                if (fishDB == null)
                {
                    return(null);
                }

                FishTO fishTO = new FishTO();
                fishTO.id      = fishDB.id;
                fishTO.tripId  = (int)fishDB.tripId;
                fishTO.name    = fishDB.name;
                fishTO.weight  = (double)fishDB.weight;
                fishTO.length  = (double)fishDB.length;
                fishTO.species = fishDB.species;
//                fishTO.notes = System.Text.Encoding.UTF8.GetString(fishDB.notes);
                fishTO.notes = fishDB.notes;
                if (fishDB.caughtDate != null)
                {
                    fishTO.caughtDate = ((DateTime)fishDB.caughtDate).ToString("yyyy-MM-dd");
                    fishTO.caughtTime = ((DateTime)fishDB.caughtDate).TimeOfDay.ToString("HH:mm:ss tt");
                }
                return(fishTO);
            }
        }
Beispiel #7
0
        public List <FishTO> GetAllFishForTripId(int tripId, string token)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var guid  = new Guid(token);
                var query = (from fish in db.Fish
                             join trip in db.Trips on fish.tripId.Value equals trip.id
                             join user in db.Users on trip.userId.Value equals user.id
                             where user.token == guid && trip.id == tripId
                             select fish);

                List <FishTO> fishes = new List <FishTO>();

                foreach (var f in query)
                {
                    FishTO fish = new FishTO();
                    fish.id      = f.id;
                    fish.tripId  = (int)f.tripId;
                    fish.name    = f.name;
                    fish.notes   = f.notes;
                    fish.weight  = (double)f.weight;
                    fish.length  = (double)f.length;
                    fish.species = f.species;
                    if (f.caughtDate != null)
                    {
                        fish.caughtDate = ((DateTime)f.caughtDate).ToString("yyyy-MM-dd");
                        fish.caughtTime = ((DateTime)f.caughtDate).TimeOfDay.ToString("HH:mm:ss tt");
                    }
                    fishes.Add(fish);
                }

                return(fishes);
            }
        }
Beispiel #8
0
        public List<FishTO> GetAllFishForUserId(int id)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var query = (from fish in db.Fish
                             join trip in db.Trips on fish.tripId equals trip.id
                             where trip.id == id
                             select fish);

                List<FishTO> fishes = new List<FishTO>();

                foreach (var fsh in query)
                {
                    FishTO fish = new FishTO();
                    fish.id = fsh.id;
                    fish.name = fsh.name;
                    fish.species = fsh.species;
                    fish.tripId = (int)fsh.tripId;
                    fish.weight = (double)fsh.weight;
                    fish.length = (double)fsh.length;
                    if (fsh.caughtDate != null)
                        fish.caughtDate = ((DateTime)fsh.caughtDate).ToString("yyyy-MM-dd");
                    fishes.Add(fish);
                }

                return fishes;
            }
        }
Beispiel #9
0
        public string CreateFish(FishTO fishTO, string token)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                Fish fishDB = new Fish();
                fishDB.name = fishTO.name;
                fishDB.species = fishTO.species;
                fishDB.length = fishTO.length;
                fishDB.weight = fishTO.weight;
                fishDB.caughtDate = DateTime.ParseExact(fishTO.caughtDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                fishDB.tripId = fishTO.tripId;

                db.Fish.Add(fishDB);
                db.SaveChanges();
            }
            return null;
        }
Beispiel #10
0
        public string CreateFish(FishTO fishTO, string token)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                Fish fishDB = new Fish();
                fishDB.name    = fishTO.name;
                fishDB.species = fishTO.species;
                fishDB.length  = fishTO.length;
                fishDB.weight  = fishTO.weight;
                fishDB.notes   = fishTO.notes;
                string date = fishTO.caughtDate + " " + fishTO.caughtTime;
                fishDB.caughtDate = DateTime.ParseExact(fishTO.caughtDate, "yyyy-MM-dd HH:mm:ss tt", CultureInfo.InvariantCulture);
                fishDB.tripId     = fishTO.tripId;

                db.Fish.Add(fishDB);
                db.SaveChanges();
            }
            return(null);
        }
Beispiel #11
0
        public List <FishTO> PostSearch(FishTO search)
        {
            List <FishTO> ftos = new List <FishTO>();

            if (search.name != null && search.name != "")
            {
                using (var db = new Fish360Project.f360Entities())
                {
                    var fishes = (from fish in db.Fish where fish.name.Contains(search.name) select fish);

                    foreach (Fish fsh in fishes)
                    {
                        FishTO fishTO = new FishTO();
                        fishTO.id      = fsh.id;
                        fishTO.name    = fsh.name;
                        fishTO.species = fsh.species;
                        fishTO.tripId  = (int)fsh.tripId;
                        fishTO.weight  = (double)fsh.weight;
                        fishTO.length  = (double)fsh.length;
                        if (fsh.caughtDate != null)
                        {
                            fishTO.caughtDate = ((DateTime)fsh.caughtDate).ToString("yyyy-MM-dd HH:mm:ss tt");
                        }

                        fishTO.girth        = fsh.girth;
                        fishTO.spot         = fsh.spot;
                        fishTO.presentation = fsh.presentation;
                        fishTO.depth        = fsh.depth;
                        fishTO.clarity      = fsh.clarity;
                        fishTO.temperature  = fsh.temperature;

                        ftos.Add(fishTO);
                    }
                }
            }

            return(ftos);
        }
Beispiel #12
0
        public FishTO GetFishForId(int id)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var fsh = (from fish in db.Fish
                           where fish.id == id
                           select fish).FirstOrDefault();

                if (fsh == null)
                {
                    return(null);
                }

                FishTO fishTO = new FishTO();
                fishTO.id      = fsh.id;
                fishTO.name    = fsh.name;
                fishTO.species = fsh.species;
                fishTO.notes   = fsh.notes;
                fishTO.tripId  = (int)fsh.tripId;
                fishTO.weight  = (double)fsh.weight;
                fishTO.length  = (double)fsh.length;

                fishTO.girth        = fsh.girth;
                fishTO.spot         = fsh.spot;
                fishTO.presentation = fsh.presentation;
                fishTO.depth        = fsh.depth;
                fishTO.clarity      = fsh.clarity;
                fishTO.temperature  = fsh.temperature;

                if (fsh.caughtDate != null)
                {
                    fishTO.caughtDate = ((DateTime)fsh.caughtDate).ToString("yyyy-MM-dd HH:mm:ss tt");
                }

                return(fishTO);
            }
        }
Beispiel #13
0
        public List<FishTO> PostSearch(FishTO search)
        {
            List<FishTO> ftos = new List<FishTO>();

            if(search.name != null && search.name != "")
            {
                using (var db = new Fish360Project.f360Entities())
                {
                    var fishes = (from fish in db.Fish where fish.name.Contains(search.name) select fish);

                    foreach (Fish fsh in fishes)
                    {
                        FishTO fishTO = new FishTO();
                        fishTO.id = fsh.id;
                        fishTO.name = fsh.name;
                        fishTO.species = fsh.species;
                        fishTO.tripId = (int)fsh.tripId;
                        fishTO.weight = (double)fsh.weight;
                        fishTO.length = (double)fsh.length;
                        if (fsh.caughtDate != null)
                            fishTO.caughtDate = ((DateTime)fsh.caughtDate).ToString("yyyy-MM-dd HH:mm:ss tt");

                        fishTO.girth = fsh.girth;
                        fishTO.spot = fsh.spot;
                        fishTO.presentation = fsh.presentation;
                        fishTO.depth = fsh.depth;
                        fishTO.clarity = fsh.clarity;
                        fishTO.temperature = fsh.temperature;

                        ftos.Add(fishTO);
                    }
                }
            }

            return ftos;
        }
Beispiel #14
0
        public void Post([FromBody] FishTO fishTO)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                Fish newFish = new Fish();
                newFish.name       = fishTO.name;
                newFish.species    = fishTO.species;
                newFish.length     = fishTO.length;
                newFish.weight     = fishTO.weight;
                newFish.notes      = fishTO.notes;
                newFish.caughtDate = DateTime.Parse(fishTO.caughtDate);//, "yyyy-MM-dd HH:mm:ss tt", CultureInfo.InvariantCulture);
                newFish.tripId     = (int)fishTO.tripId;

                newFish.girth        = fishTO.girth;
                newFish.spot         = fishTO.spot;
                newFish.presentation = fishTO.presentation;
                newFish.depth        = fishTO.depth;
                newFish.clarity      = fishTO.clarity;
                newFish.temperature  = fishTO.temperature;

                db.Fish.Add(newFish);
                db.SaveChanges();
            }
        }
Beispiel #15
0
        public string UpdateFish(FishTO fishTO, string token)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var guid = new Guid(token);
                var fishDB = (from fish in db.Fish
                             where fish.id == fishTO.id
                             select fish).FirstOrDefault();
                if (fishDB == null)
                    return null;

                db.Fish.Attach(fishDB);

                fishDB.name = fishTO.name;
                fishDB.species = fishTO.species;
                fishDB.length = fishTO.length;
                fishDB.weight = fishTO.weight;
                fishDB.notes = fishTO.notes;
                string date = fishTO.caughtDate + " " + fishTO.caughtTime;
                fishDB.caughtDate = DateTime.ParseExact(fishTO.caughtDate, "yyyy-MM-dd HH:mm:ss tt", CultureInfo.InvariantCulture);

                db.SaveChanges();
            }
            return null;
        }
Beispiel #16
0
        public FishTO GetFishForId(int fishId, string token)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var guid = new Guid(token);
                var fishDB = (from fishLQ in db.Fish
                             where fishLQ.id == fishId
                             select fishLQ).FirstOrDefault();
                if (fishDB == null)
                    return null;

                FishTO fishTO = new FishTO();
                fishTO.id = fishDB.id;
                fishTO.tripId = (int)fishDB.tripId;
                fishTO.name = fishDB.name;
                fishTO.weight = (double)fishDB.weight;
                fishTO.length = (double)fishDB.length;
                fishTO.species = fishDB.species;
            //                fishTO.notes = System.Text.Encoding.UTF8.GetString(fishDB.notes);
                fishTO.notes = fishDB.notes;
                if (fishDB.caughtDate != null)
                {
                    fishTO.caughtDate = ((DateTime)fishDB.caughtDate).ToString("yyyy-MM-dd");
                    fishTO.caughtTime = ((DateTime)fishDB.caughtDate).TimeOfDay.ToString("HH:mm:ss tt");
                }
                return fishTO;
            }
        }
Beispiel #17
0
        public FishTO GetFishForId(int id)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var fsh = (from fish in db.Fish
                             where fish.id == id
                             select fish).FirstOrDefault();

                if (fsh == null)
                    return null;

                FishTO fishTO = new FishTO();
                fishTO.id = fsh.id;
                fishTO.name = fsh.name;
                fishTO.species = fsh.species;
                fishTO.tripId = (int)fsh.tripId;
                fishTO.weight = (double)fsh.weight;
                fishTO.length = (double)fsh.length;
                if (fsh.caughtDate != null)
                    fishTO.caughtDate = ((DateTime)fsh.caughtDate).ToString("yyyy-MM-dd");

                return fishTO;
            }
        }
Beispiel #18
0
        public FishTO GetFishForId(int id)
        {
            using (var db = new Fish360Project.f360Entities())
            {
                var fsh = (from fish in db.Fish
                             where fish.id == id
                             select fish).FirstOrDefault();

                if (fsh == null)
                    return null;

                FishTO fishTO = new FishTO();
                fishTO.id = fsh.id;
                fishTO.name = fsh.name;
                fishTO.species = fsh.species;
                fishTO.notes = fsh.notes;
                fishTO.tripId = (int)fsh.tripId;
                fishTO.weight = (double)fsh.weight;
                fishTO.length = (double)fsh.length;

                fishTO.girth = fsh.girth;
                fishTO.spot = fsh.spot;
                fishTO.presentation = fsh.presentation;
                fishTO.depth = fsh.depth;
                fishTO.clarity = fsh.clarity;
                fishTO.temperature = fsh.temperature;

                if (fsh.caughtDate != null)
                    fishTO.caughtDate = ((DateTime)fsh.caughtDate).ToString("yyyy-MM-dd HH:mm:ss tt");

                return fishTO;
            }
        }