public void IsValidPhoneNumber_WithCountryCode_True()
        {
            // Arrange
            var number = "447001002003";
            // Act
            var result = _helper.IsValidMobileNumber(number);

            // Assert
            Assert.IsTrue(result);
        }
示例#2
0
        /// <summary>
        /// Createa a new user and returns a string for logging
        /// </summary>
        /// <param name="user"></param>
        /// <param name="saveChangesImmediatly"></param>
        /// <returns></returns>
        public string CreateUser(UserInfoModel user, bool saveChangesImmediatly = true)
        {
            if (!_phoneNumberHelper.IsValidMobileNumber(user.PhoneNumber))
            {
                return($"INVALID, {user.FirstName}, {user.LastName}, {user.PhoneNumber}");
            }

            // Check for existing user (using phone number) as users may be uploaded several times
            var existingUser = Fit2WorkDb.Users
                               .FirstOrDefault(u => u.ClientId == user.ClientId &&
                                               u.PhoneNumber.Equals(user.PhoneNumber));

            if (existingUser != null)
            {
                // Found an existing user - update and save
                user.Id = existingUser.Id;
                existingUser.FirstName   = user.FirstName;
                existingUser.LastName    = user.LastName;
                existingUser.UpdatedDate = user.UpdatedDate = DateTime.UtcNow;
            }
            else
            {
                // Create user for the first time
                user.CreatedDate = DateTime.UtcNow;
                Fit2WorkDb.Users.Add(user);
            }

            if (saveChangesImmediatly)
            {
                Fit2WorkDb.SaveChanges();
            }

            var createdUpdated = existingUser == null ? "CREATED" : "UPDATED";

            return($"{createdUpdated}, {user.FirstName}, {user.LastName}, {user.PhoneNumber}");
        }