Exemplo n.º 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());
        }
Exemplo n.º 2
0
 // check if the code can be sent
 private void btSendCode_Click(object sender, EventArgs e)
 {
     if (tbEmail.Text.Trim() != string.Empty)
     {
         if (tbEmail.Text.Trim().IsValidEmail())
         {
             var email = new BaseRepository <UserEmail>().Get(x => x.EmailName == tbEmail.Text.Trim());
             if (email.Any())
             {
                 tbCodeFromEmail.Text = RandomStrings.ReceivedResetCode();
             }
             else
             {
                 MessageContainer.DisplayError("Email not found", "Error");
             }
         }
         else
         {
             MessageContainer.DisplayError("Please, enter valid email", "Error");
         }
     }
     else
     {
         MessageContainer.DisplayError("You should enter email first", "Email not entered");
     }
 }
Exemplo n.º 3
0
        public object Get(GetEventUsersRequest Request)
        {
            User user = base.GetAuthenticatedUser(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            Event Event = Request.GetEntity(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            IQueryable <Match> Matches = new BaseRepository <Match>(((NHibernate.ISession)base.Request.Items["hibernateSession"]))
                                         .List(x => x.Event.Id == Event.Id &&
                                               (
                                                   (x.FirstUser.Id == user.Id && x.IsFirstUserLike != null) ||
                                                   (x.SecondUser.Id == user.Id && x.IsSecondUserLike != null)
                                               )
                                               );

            IEnumerable <User> Users = Event.User.Where(x => x.Id != user.Id &&
                                                        !Matches.Any(y => y.FirstUser.Id == x.Id || y.SecondUser.Id == x.Id)
                                                        );

            int userAge = (new DateTime(1, 1, 1) + (DateTime.Now - user.Birthday)).Year - 1;

            Users = Users.Where(x => x.UserPreferences != null && user.UserPreferences != null &&
                                user.UserPreferences.Gender.Contains(x.Gender) && x.UserPreferences.Gender.Contains(user.Gender)
                                );

            Users = Users.Where(x => x.UserPreferences != null && user.UserPreferences != null
                                &&
                                (
                                    userAge >= x.UserPreferences.AgeStart &&
                                    userAge <= x.UserPreferences.AgeEnd
                                )
                                );

            Users = Users.Where(x => x.UserPreferences != null && user.UserPreferences != null
                                &&
                                (
                                    (new DateTime(1, 1, 1) + (DateTime.Now - x.Birthday)).Year - 1 >= user.UserPreferences.AgeStart &&
                                    (new DateTime(1, 1, 1) + (DateTime.Now - x.Birthday)).Year - 1 <= user.UserPreferences.AgeEnd
                                )
                                );

            if (Request.limit > 0)
            {
                Users = Users.Take(Request.limit);
            }

            return(new GetEventUsersResponse(user, Users, ((NHibernate.ISession)base.Request.Items["hibernateSession"])));
        }
Exemplo n.º 4
0
        // function searches a user in the db by id / login / id + login
        private void btSearch_Click(object sender, EventArgs e)
        {
            //check if search criteria have been entered
            if (tbSearchLogin.Text.Trim() == String.Empty &&
                tbSurname.Text.Trim() == String.Empty &&
                numSearchUserId.Value == 0)
            {
                MessageContainer.DisplayError("Please, set search criteria", "Error");
            }
            else
            {
                var foundUsers = new BaseRepository <User>().GetAll();

                // try to find by Name
                if (tbSearchName.Text.Trim() != string.Empty)
                {
                    foundUsers = foundUsers.Where(x => x.FirstName == tbSearchName.Text.Trim());
                }

                // try to find by Surname
                if (tbSearchSurname.Text.Trim() != string.Empty)
                {
                    foundUsers = foundUsers.Where(x => x.LastName == tbSearchSurname.Text.Trim());
                }

                // try to find by login
                if (tbSearchLogin.Text.Trim() != string.Empty)
                {
                    foundUsers = foundUsers.Where(x => x.Login == tbSearchLogin.Text.Trim());
                }

                // try to find by Id
                if (numSearchUserId.Value != 0)
                {
                    foundUsers = foundUsers.Where(x => x.Id == numSearchUserId.Value);
                }

                if (!foundUsers.Any())
                {
                    MessageContainer.DisplayError("No users found according to selected criteria", "Error");
                    return;
                }
                FillUsersLv(foundUsers);
            }
        }
Exemplo n.º 5
0
        public object Delete(DeletePushRequest Request)
        {
            DeviceToken deviceToken = Request.GetEntity(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            deviceToken.User = GetAuthenticatedUser(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            List <DeviceToken> deviceTokens = new BaseRepository <DeviceToken>(((NHibernate.ISession)base.Request.Items["hibernateSession"])).List(x =>
                                                                                                                                                   x.Platform == deviceToken.Platform &&
                                                                                                                                                   x.Token == deviceToken.Token
                                                                                                                                                   ).ToList();

            if (deviceTokens != null && deviceTokens.Any())
            {
                deviceTokens.First().Delete(((NHibernate.ISession)base.Request.Items["hibernateSession"]));
            }

            return(new BaseResponse());
        }
Exemplo n.º 6
0
        private void LoadAllChannelsList()
        {
            //var number = 1;
            var allChannels = new BaseRepository <Channel>().GetAll().ToList();

            if (!allChannels.Any())
            {
                return;
            }

            ListViewItem[] arrChannelItems = ChannelsToListViewItem(allChannels).ToArray();

            lvChannelsList.BeginUpdate();

            ListView.ListViewItemCollection lvic = new ListView.ListViewItemCollection(lvChannelsList);
            lvic.AddRange(arrChannelItems);

            lvChannelsList.EndUpdate();
        }
Exemplo n.º 7
0
 /// <summary>
 /// 是否存在
 /// </summary>
 /// <param name="anyLambda">查询表达式</param>
 /// <returns>布尔值</returns>
 public bool Exist(Expression <Func <T, bool> > anyLambda)
 {
     return(_baseRepository.Any(anyLambda));
 }
Exemplo n.º 8
0
 public bool Any(Expression <Func <T, bool> > exp)
 {
     return(_baseRep.Any(exp));
 }
Exemplo n.º 9
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));
        }