Ejemplo n.º 1
0
        public IActionResult GetUserInterest()
        {
            BaseResult <UserModel> baseResult = new BaseResult <UserModel>();
            int userId = Convert.ToInt32(HttpContext.User.Identity.Name);

            baseResult.data.userInterest = _SUserInterest.GetUserInterest(userId);
            return(Json(baseResult));
        }
Ejemplo n.º 2
0
        public IActionResult GetActiveEvents()
        {
            BaseResult <EventModel> baseResult = new BaseResult <EventModel>();
            bool isAuthenticated = HttpContext.User.Identity.IsAuthenticated;

            if (isAuthenticated)
            {
                int  userId = Convert.ToInt32(HttpContext.User.Identity.Name);
                User user   = _SUser.GetById(userId);
                if (_SUserInterest.GetUserInterest(userId).Count > 0)
                {
                    string sql = @"SELECT e.*,ct.name 'CountryName',ci.name 'CityName',CONCAT(u.name,' ',u.surname)
                    'creatorName' FROM event e
                    INNER JOIN eventcategory eg ON eg.eventId = e.id
                    INNER JOIN country ct ON ct.id = e.countryId
                    INNER JOIN city ci ON ci.id = e.cityId
                    INNER JOIN user u ON u.id = e.userId
                    WHERE e.statusId = 2 AND e.endDate> NOW() AND eg.categoryId IN (
                    SELECT ui.interestId FROM user u
                    INNER JOIN userinterest ui ON u.id = ui.userId
                    WHERE u.id = @userId AND ui.statusId = 2  GROUP BY ui.interestId
                    ) AND e.countryId = @countryId AND e.cityId = @cityId ORDER BY e.id ASC";
                    baseResult.data.events = _SEvent.GetEvents(sql, new {
                        userId    = userId,
                        countryId = user.countryId,
                        cityId    = user.cityId
                    });
                }
                else
                {
                    string sql = @"SELECT e.*,ct.name 'CountryName', ci.name 'CityName', CONCAT(u.name,' ',u.surname) AS 'creatorName'
                    FROM event e
                    INNER JOIN country ct ON ct.id = e.countryId
                    INNER JOIN city ci ON ci.id= e.cityId
                    INNER JOIN user u ON u.id = e.userId
                    WHERE e.statusId = 2 AND e.endDate > NOW() AND ct.id = @countryId AND ci.id = @cityId ORDER BY e.id ASC";
                    baseResult.data.events = _SEvent.GetEvents(sql, new {
                        countyId = user.countryId,
                        cityId   = user.cityId
                    });
                }
            }
            else
            {
                string sql = @"SELECT e.*,ct.name 'CountryName', ci.name 'CityName', CONCAT(u.name,' ',u.surname) AS 'creatorName' FROM event e
                    INNER JOIN country ct ON ct.id = e.countryId
                    INNER JOIN city ci ON ci.id= e.cityId
                    INNER JOIN user u ON u.id = e.userId
                WHERE e.endDate > NOW() AND e.statusId = 2 ORDER BY e.id ASC";
                baseResult.data.events = _SEvent.GetEvents(sql, new { });
            }
            var          distinctItems = baseResult.data.events.GroupBy(x => x.id).Select(y => y.First());
            List <Event> temp          = new List <Event>();

            foreach (var item in distinctItems)
            {
                temp.Add(item);
            }
            baseResult.data.events = temp;
            return(Json(baseResult));
        }