예제 #1
0
        public UserVisits GetByUserIdWithParametrs(int userId, uint?fromDate, uint?toDate, string country, int?toDistance)
        {
            IQueryable <Visit> visits = _repository.AsQueryable <Visit>().Where(n => n.User == userId);

            if (fromDate != null)
            {
                visits = visits.Where(n => n.Visited_at > fromDate);
            }
            if (toDate != 0)
            {
                visits = visits.Where(n => n.Visited_at < toDate);
            }
            uint[] arrayIds = _locationProvider.GetIdByCountryAndDistance(country, toDistance);
            if (arrayIds.Count() > 0)
            {
                visits = visits.Where(n => arrayIds.Contains(n.Location));
            }
            UserVisits userVisits = new UserVisits();

            userVisits.Visits = visits.Select(n => new VisitDetail()
            {
                Mark       = n.Mark,
                Visited_at = n.Visited_at,
                Place      = _locationProvider.GetById(n.Location).Place
            }).AsParallel()
                                .OrderBy(m => m.Visited_at).ToList();
            return(userVisits);
        }
예제 #2
0
        public JsonResult Get(int id, [FromQuery] UInt32?fromDate, [FromQuery] UInt32 toDate, [FromQuery] string country, [FromQuery] int?toDistance)
        {
            User user = _userProvider.GetById(id);

            if (user.Id == 0)
            {
                return(new JsonResult(new object())
                {
                    StatusCode = 404
                });
            }
            UserVisits visits = _visitProvider.GetByUserIdWithParametrs(id, fromDate, toDate, country, toDistance);

            if (visits == null)
            {
                return(new JsonResult(new object())
                {
                    StatusCode = 404
                });
            }
            return(new JsonResult(visits));
        }
예제 #3
0
        public void LogMemberVisit(Guid visitingUserID, Guid userID)
        {
            if (visitingUserID == userID)
                return;

            var visit = Entities.UserVisits.FirstOrDefault(x => x.VisitingUserId == visitingUserID && x.UserId == userID);

            if (visit == null) // first time
            {
                visit = new UserVisits {UserId = userID, VisitingUserId = visitingUserID};
                Entities.UserVisits.AddObject(visit);
            }

            visit.TimeStamp = DateTime.Now;
            Entities.SaveChanges();
        }
예제 #4
0
        public void LogAnonymousVisit(Guid userID)
        {
            UserVisits visit = Entities.UserVisits.FirstOrDefault(x => x.VisitingUserId == null && x.UserId == userID);
            if (visit == null)
            {
                visit = new UserVisits();
                Entities.UserVisits.AddObject(visit);
            }
            visit.VisitingUserId = null;
            visit.UserId = userID;

            visit.TimeStamp = DateTime.Now;
            Entities.SaveChanges();
        }
예제 #5
0
 public void Delete(UserVisits entity)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 public void Add(UserVisits visit)
 {
     _entities.UserVisits.AddObject(visit);
 }