예제 #1
0
        public object Post(PostMessageRequest Request)
        {
            Message message = Request.GetEntity(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            message.FromUser = GetAuthenticatedUser(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            message.Save(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            message.Match.Save(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            User user = message.ToUser;

            List <DeviceToken> deviceToken = new BaseRepository <DeviceToken>(((NHibernate.ISession)base.Request.Items["hibernateSession"])).List(x =>
                                                                                                                                                  x.User.Id == user.Id).ToList();

            if (deviceToken != null && deviceToken.Any())
            {
                try
                {
                    PushHelper.SendNotification(deviceToken, "Nova mensagem de " + message.FromUser.Name, "message");
                }
                catch {
                }
            }

            return(new BaseResponse());
        }
예제 #2
0
        public object Post(PostMatchLikeRequest Request)
        {
            User AuthenticatedUser = GetAuthenticatedUser(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            User user = new User().Get(Request.userID, ((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            Event event_ = new Event().Get(Request.eventID, ((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            Match match = new BaseRepository <Match>(((NHibernate.ISession)base.Request.Items["hibernateSession"])).List(x =>
                                                                                                                         x.FirstUser == user && x.SecondUser == AuthenticatedUser &&
                                                                                                                         x.Event == event_).FirstOrDefault();

            if (match == null)
            {
                match = new Match()
                {
                    Event           = event_,
                    FirstUser       = AuthenticatedUser,
                    DateFirstUser   = DateTime.Now,
                    IsFirstUserLike = Request.isLike,
                    SecondUser      = user
                };
            }
            else
            {
                match.DateSecondUser   = DateTime.Now;
                match.IsSecondUserLike = Request.isLike;
            }

            match.Save(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            if (match.IsFirstUserLike &&
                match.IsSecondUserLike != null &&
                match.IsSecondUserLike == true)
            {
                User firstUser = match.FirstUser;

                List <DeviceToken> deviceToken = new BaseRepository <DeviceToken>(((NHibernate.ISession)base.Request.Items["hibernateSession"])).List(x =>
                                                                                                                                                      x.User.Id == firstUser.Id).ToList();

                if (deviceToken != null && deviceToken.Any())
                {
                    PushHelper.SendNotification(deviceToken, "Novo Match com " + match.SecondUser.Name, "match");
                }
            }

            /*
             * IQueryable<Match> Matches = new BaseRepository<Match>(((NHibernate.ISession)base.Request.Items["hibernateSession"])).List(x =>
             *      x.SecondUser != null
             *      &&
             *      (
             *              (x.FirstUser == match.FirstUser && x.SecondUser == match.SecondUser)
             ||
             ||             (x.FirstUser == match.SecondUser && x.SecondUser == match.FirstUser)
             ||     )
             ||     &&
             ||     (x.IsFirstUserLike && x.IsSecondUserLike != null && x.IsSecondUserLike == true)
             ||).OrderBy(y => y.Created);
             */

            return(new PostMatchLikeResponse(match));
        }