Beispiel #1
0
        public List <LocationEntryViewModel> DiaryEntries()
        {
            var userId  = User.Identity.GetUserId();
            var AppUser = db.Users.Find(userId);
            List <LocationEntryViewModel> diary = new List <LocationEntryViewModel>();

            if (AppUser.Diary != null && AppUser.Diary.Count != 0)
            {
                foreach (LocationEntry entry in AppUser.Diary)
                {
                    var diaryEntry = new LocationEntryViewModel()
                    {
                        Address         = entry.Location.DisplayFriendlyName,
                        BadgeNames      = entry.LocationBadge.Select(x => x.BadgeName).ToList(),
                        CheckIns        = entry.Visits.Select(x => x.DateCreated.ToString()).ToList(),
                        Latitude        = entry.Location.Latitude,
                        Longitude       = entry.Location.Longitude,
                        DateCreated     = entry.DateCreated.ToString(),
                        Comments        = entry.Comments,
                        LocationEntryID = entry.DiaryEntryID
                    };
                    diary.Add(diaryEntry);
                }
            }
            return(diary);
        }
Beispiel #2
0
        private bool createTripEntry(LocationEntryViewModel location, LocationEntry entry, ApplicationUser user)
        {
            Location loc = new Location()
            {
                DisplayFriendlyName = location.Address,
                Latitude            = location.Latitude,
                Longitude           = location.Longitude,
            };
            CheckIn checkIn = new CheckIn()
            {
                DateCreated = DateTime.Now,
                Location    = loc,
            };
            List <CheckIn> visits = new List <CheckIn>()
            {
                checkIn
            };
            List <Badge> badges     = new List <Badge>();
            List <Badge> badgesInDb = db.Badges.ToList();
            Trip         trip       = user.Trips.Where(x => x.TripName == location.tripName).FirstOrDefault();

            if (trip == null)
            {
                return(false);
            }
            foreach (string badge in location.BadgeNames)
            {
                if (badgesInDb.Where(x => x.BadgeName == badge) == null)
                {
                    badges.Add(new Badge()
                    {
                        BadgeName = badge
                    });
                }
                else
                {
                    badges.Add(badgesInDb.Where(x => x.BadgeName == badge).FirstOrDefault());
                }
            }
            if (entry == null)
            {
                entry = new LocationEntry()
                {
                    DateCreated   = DateTime.Now,
                    Location      = loc,
                    LocationBadge = badges,
                    Visits        = visits,
                    Comments      = location.Comments
                };
                trip.TripEntries.Add(entry);
            }
            else
            {
                entry.Visits.Add(checkIn);
                entry.LocationBadge = badges;
            }
            db.SaveChanges();
            return(true);
        }
Beispiel #3
0
        private bool createLocationEntry(LocationEntryViewModel location, LocationEntry entry, ApplicationUser user)
        {
            Location loc = new Location()
            {
                DisplayFriendlyName = location.Address,
                Latitude            = location.Latitude,
                Longitude           = location.Longitude,
            };
            CheckIn checkIn = new CheckIn()
            {
                DateCreated = DateTime.Now,
                Location    = loc,
            };
            List <CheckIn> visits = new List <CheckIn>()
            {
                checkIn
            };
            List <Badge> badges     = new List <Badge>();
            List <Badge> badgesInDb = db.Badges.ToList();

            foreach (string badge in location.BadgeNames)
            {
                badges.Add(new Badge()
                {
                    BadgeName = badge
                });
            }
            if (entry == null)
            {
                entry = new LocationEntry()
                {
                    DateCreated   = DateTime.Now,
                    Location      = loc,
                    LocationBadge = badges,
                    Visits        = visits,
                    Comments      = location.Comments
                };
                user.Diary.Add(entry);
            }
            else
            {
                entry.Visits.Add(checkIn);
                entry.LocationBadge = badges;
            }
            db.SaveChanges();
            return(true);
        }
Beispiel #4
0
        public IHttpActionResult emergencyCheckIn(LocationEntryViewModel entry)
        {
            var           userId   = User.Identity.GetUserId();
            var           AppUser  = db.Users.Find(userId);
            LocationEntry location = new LocationEntry();

            location.Comments    = entry.Comments;
            location.DateCreated = DateTime.Now;
            location.Location    = new Location()
            {
                DisplayFriendlyName = entry.Address,
                Latitude            = entry.Latitude,
                Longitude           = entry.Longitude
            };
            AppUser.emergencyCheckIn = location;
            db.SaveChanges();
            return(Ok());
        }
Beispiel #5
0
 public IHttpActionResult createEntry(LocationEntryViewModel location)
 {
     if (location == null)
     {
         return(BadRequest());
     }
     try
     {
         var userId  = User.Identity.GetUserId();
         var AppUser = db.Users.Find(userId);
         if (location.tripName == null || location.tripName == "" || location.tripName == "My Diary")
         {
             LocationEntry entry = AppUser.Diary
                                   .Where(x => x.Location.DisplayFriendlyName == location.Address)
                                   .FirstOrDefault();
             if (!createLocationEntry(location, entry, AppUser))
             {
                 return(BadRequest());
             }
             ;
         }
         else
         {
             LocationEntry tripentry = AppUser
                                       .Trips
                                       .Where(x => x.TripName == location.tripName)
                                       .SelectMany(x => x.TripEntries)
                                       .Where(x => x.Location.DisplayFriendlyName == location.Address)
                                       .FirstOrDefault();
             if (!createTripEntry(location, tripentry, AppUser))
             {
                 return(BadRequest());
             }
             ;
         }
         return(Ok());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Beispiel #6
0
        public LocationEntryViewModel getEmergencyCheckIn(string Username)
        {
            var userId  = User.Identity.GetUserId();
            var AppUser = db.Users.FirstOrDefault(x => x.UserName == Username);
            LocationEntryViewModel loc   = new LocationEntryViewModel();
            LocationEntry          entry = AppUser.emergencyCheckIn;

            if (entry == null)
            {
                return(null);
            }
            else
            {
                loc.Address     = entry.Location.DisplayFriendlyName;
                loc.Comments    = entry.Comments;
                loc.DateCreated = entry.DateCreated.ToString();
                loc.Latitude    = entry.Location.Latitude;
                loc.Longitude   = entry.Location.Longitude;
            }
            return(loc);
        }
Beispiel #7
0
        private List <LocationEntryViewModel> mapLocationEntrytoViewModel(Trip trip)
        {
            List <LocationEntryViewModel> levms = new List <LocationEntryViewModel>();

            foreach (LocationEntry entry in trip.TripEntries)
            {
                LocationEntryViewModel levm = new LocationEntryViewModel()
                {
                    Address         = entry.Location.DisplayFriendlyName,
                    Comments        = entry.Comments,
                    DateCreated     = entry.DateCreated.ToString(),
                    Latitude        = entry.Location.Latitude,
                    Longitude       = entry.Location.Longitude,
                    tripName        = trip.TripName,
                    LocationEntryID = entry.DiaryEntryID,
                    BadgeNames      = entry.LocationBadge.Select(x => x.BadgeName).ToList(),
                    CheckIns        = entry.Visits.Select(x => x.DateCreated.ToString()).ToList()
                };
                levms.Add(levm);
            }
            return(levms);
        }
Beispiel #8
0
        public List <LocationEntryViewModel> UserDiaryEntries(string Username)
        {
            string userId  = User.Identity.GetUserId();
            var    AppUser = db.Users.Find(userId);

            if (Username != null && Username != "")
            {
                if (!db.Users.Where(x => x.UserName == Username).FirstOrDefault().UserSettings.Safemode)
                {
                    AppUser = db.Users.Where(x => x.UserName == Username).FirstOrDefault();
                }
                else
                {
                    return(null);
                }
            }
            List <LocationEntryViewModel> diary = new List <LocationEntryViewModel>();

            if (AppUser.Diary != null && AppUser.Diary.Count != 0)
            {
                foreach (LocationEntry entry in AppUser.Diary)
                {
                    var diaryEntry = new LocationEntryViewModel()
                    {
                        Address         = entry.Location.DisplayFriendlyName,
                        BadgeNames      = entry.LocationBadge.Select(x => x.BadgeName).ToList(),
                        CheckIns        = entry.Visits.Select(x => x.DateCreated.ToString()).ToList(),
                        Latitude        = entry.Location.Latitude,
                        Longitude       = entry.Location.Longitude,
                        DateCreated     = entry.DateCreated.ToString(),
                        Comments        = entry.Comments,
                        LocationEntryID = entry.DiaryEntryID
                    };
                    diary.Add(diaryEntry);
                }
            }
            return(diary);
        }
Beispiel #9
0
 public LocationEntry()
 {
     InitializeComponent();
     this.DataContext = LEVM = new ViewModels.LocationEntryViewModel();
 }