public void SaveTourist(NewTouristModel newTourist)
        {
            using (var db = new SitesEntities())
            {
                var searchedTourist = (from t in db.Tourists
                                       where t.AndroidID.Equals(newTourist.AndroidID) == true
                                       select t).FirstOrDefault();
                if (searchedTourist == null)
                {
                    Tourist addTourist = new Tourist();
                    addTourist.AndroidID    = newTourist.AndroidID;
                    addTourist.Username     = newTourist.Username;
                    addTourist.VisitedSites = 0;
                    db.Tourists.Add(addTourist);
                    db.SaveChanges();
                }

                if (searchedTourist != null)
                {
                    var updateTourist = db.Tourists.Find(searchedTourist.ID);
                    updateTourist.VisitedSites = newTourist.VisitedSites;
                    updateTourist.Username     = newTourist.Username;
                    db.SaveChanges();
                }
            }
        }
 public void SaveComment(PostCommentModel postedComment)
 {
     using (var db = new SitesEntities())
     {
         SiteComment newComment = new SiteComment();
         newComment.UserName = postedComment.UserName;
         newComment.Comment  = postedComment.Comment;
         newComment.SiteID   = postedComment.SiteID;
         db.SiteComments.Add(newComment);
         db.SaveChanges();
     }
 }
        public void SaveEvent(PostedEventModel postedEvent)
        {
            using (var db = new SitesEntities())
            {
                SiteEvent newEvent = new SiteEvent();
                newEvent.DateOfEvent      = postedEvent.DateOfEvent;
                newEvent.EventDescription = postedEvent.EventDescription;
                newEvent.SiteID           = postedEvent.SiteID;


                db.SiteEvents.Add(newEvent);
                db.SaveChanges();
            }
        }
 public bool CheckIfUsernameExists(string userName)
 {
     using (var db = new SitesEntities())
     {
         var usernameExists = (from t in db.Tourists
                               where t.Username.Equals(userName) == true
                               select t).FirstOrDefault();
         if (usernameExists != null)
         {
             return(true);
         }
     }
     return(false);
 }
        public void FindComments(int siteId)
        {
            using (var db = new SitesEntities())
            {
                var comments = (from c in db.SiteComments
                                where c.SiteID == siteId
                                select c);

                foreach (var comment in comments)
                {
                    var commentModel = new CommentModel();
                    commentModel.Comment  = comment.Comment;
                    commentModel.SiteID   = comment.SiteID;
                    commentModel.UserName = comment.UserName;
                    Comments.Add(commentModel);
                }
            }
        }
        public void FindEvents(int siteId)
        {
            using (var db = new SitesEntities())
            {
                var events = (from e in db.SiteEvents
                              where e.SiteID == siteId
                              select e);

                foreach (var singleEvent in events)
                {
                    var eventModel = new EventModel();
                    eventModel.Description = singleEvent.EventDescription;
                    eventModel.SiteID      = singleEvent.SiteID;
                    eventModel.DateOfEvent = singleEvent.DateOfEvent;
                    Events.Add(eventModel);
                }
            }
        }
        public ProgressAndMessageModel ReturnTouristPlace(string androidId)
        {
            ProgressAndMessageModel progress = new ProgressAndMessageModel();

            using (var db = new SitesEntities())
            {
                var searchedTourist = (from tourist in db.Tourists
                                       where tourist.AndroidID.Equals(androidId) == true
                                       select tourist).FirstOrDefault();
                if (searchedTourist != null)
                {
                    var listOfTourists = db.Tourists.OrderBy(v => v.VisitedSites).ToList();
                    listOfTourists.Reverse();
                    int place = listOfTourists.IndexOf(searchedTourist);
                    progress.ProgressNumber = place;
                    if (!String.IsNullOrWhiteSpace(searchedTourist.MessageToUser))
                    {
                        progress.Message = searchedTourist.MessageToUser;
                    }
                    return(progress);
                }
            }
            return(progress);
        }