public void BlockUser(User logedUser, string blockedUser)
 {
     using (var Context = new BMSContext())
     {
         BlockedUsers bu = new BlockedUsers();
         bu.BlockerUser = Context.Users.Where(u => u.Username == logedUser.Username).FirstOrDefault();
         bu.BlockedUser = Context.Users.Where(u => u.Username == blockedUser).FirstOrDefault();
         Context.BlockedUsers.Add(bu);
         Context.SaveChanges();
     }
 }
 public bool HideFromList(User loggedUser)
 {
     using (var Context = new BMSContext())
     {
         User user = Context.Users.Where(u => u.Username == loggedUser.Username).FirstOrDefault();
         if (user != null)
         {
             user.IsHidden = !user.IsHidden;
         }
         Context.SaveChanges();
         return(user.IsHidden);
     }
 }
Beispiel #3
0
        public int AddMessage(string senderUserName, string receiverUserName, string message)
        {
            using (var Context = new BMSContext())
            {
                if (GetSentMessagesNumberByUserSentToday(senderUserName) >= 5)
                {
                    throw new Exception("Numbers of messages per day reach the limit (5)! ");
                }
                Message newMessage = new Message();
                newMessage.Sender   = Context.Users.Where(u => u.Username.Equals(senderUserName)).FirstOrDefault();
                newMessage.Receiver = Context.Users.Where(u => u.Username.Equals(receiverUserName)).FirstOrDefault();
                newMessage.IsRead   = false;
                newMessage.Sent     = DateTime.Now;
                newMessage.Data     = message;


                Context.Messages.Add(newMessage);
                return(Context.SaveChanges());
            }
        }
        public void RegisterUser(string userName, string firstName, string lastName, string password, string phoneNumber, string email)
        {
            if (String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(firstName) || String.IsNullOrWhiteSpace(lastName) || String.IsNullOrWhiteSpace(password) || String.IsNullOrWhiteSpace(email))
            {
                throw new Exception("Mandatory fields represented with * cannot be null.");
            }
            var regex = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,}$");

            if (!regex.IsMatch(password))
            {
                throw new Exception("Password is not acceptable. \n Password rules: Small and Capital letters and number, Minimum lenght:6");
            }
            if (GetUserByUserName(userName) != null)
            {
                throw new Exception("UserName already exist, please choose another one.");
            }


            //SecureString ss = new NetworkCredential("", password).SecurePassword;
            //newUser.Password = SecurityHelper.EncryptString(ss);
            //newUser.CredentialEncryptionHash= SecurityHelper.MD5Hash(string.Format("{0}{1}",
            //userName,
            //password));
            //EncryptPassword(ref password);
            using (var Context = new BMSContext())
            {
                User newUser = new User();
                newUser.Username    = userName;
                newUser.FirstName   = firstName;
                newUser.Surname     = lastName;
                newUser.Password    = password;
                newUser.PhoneNumber = phoneNumber;
                newUser.Email       = email;
                Context.Users.Add(newUser);
                Context.SaveChanges();

                //TODO:Check mailsending settings
                //if (Context.SaveChanges() > 0)
                //    MailSender.MailSender.Send(newUser.Email, "BMS Confirmation", "Dear" + newUser.Surname + ", \nThank your for registering in BMS Message sending application. \nKind regards,\nBMS Team");
            }
        }