Example #1
0
        public List<ContactInfo> ValidatePhoneNumbers(List<ContactInfo> lstContacts, string defaultContryCode, List<TerritoryInfo> lstTerritory)
        {
            try
            {
                List<ContactInfo> lstFilteresContacts = new List<ContactInfo>();
                PhoneNumberUtil phoneUtil = PhoneNumberUtil.Instance;
                TerritoryManager mgr = new TerritoryManager();

                lstContacts.ForEach(x =>
                {
                    try
                    {
                        PhoneNumber num = CheckBasicCountryCode(x.Number, phoneUtil, defaultContryCode);
                        if (num.IsValidNumber && (num.NumberType == PhoneNumberUtil.PhoneNumberType.MOBILE || num.NumberType == PhoneNumberUtil.PhoneNumberType.FIXED_LINE_OR_MOBILE))
                        {
                            if (num.CountryCode != null)
                            {
                                x.TerritoryId = mgr.GetTerritoryIdByCountryCode(String.Format("+{0}", num.CountryCode), lstTerritory).Id;
                                x.Number = num.NationalNumber.ToString();
                                var info = lstFilteresContacts.Where(y => y.Number.Equals(x.Number)).FirstOrDefault();
                                if (info == null)
                                    lstFilteresContacts.Add(x);

                            }

                        }
                    }
                    catch (Exception ex)
                    {
                        if (!ex.Message.Equals(CodeHelper.ContactNumberNotValid))
                            throw ex;
                    }
                });

                return lstFilteresContacts;
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                throw new Exception(CodeHelper.ContactNumberNotValid);
            }
        }
Example #2
0
        public string AddUser(UserInfo info, ResourceInfo resourceInfo)
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(resourceInfo.DataUrl))
                    resourceInfo.Data = JsonWebToken.Base64UrlDecode(resourceInfo.DataUrl);

                string reqHeader = HttpContext.Current.Request.Headers[CodeHelper.HeaderAccessKey];
                if (!String.IsNullOrEmpty(reqHeader))
                {
                    // If token is valid then add user
                    if (TokenAuthorization.CheckBasicAuthorization(reqHeader))
                    {
                        UserManager mgr = new UserManager();
                        // gets territory id by country code
                        TerritoryManager trMgr = new TerritoryManager();
                        info.TerritoryId = trMgr.GetTerritoryIdByCountryCode(info.CountryCode, trMgr.GetTerritoryList()).Id;
                        if (!String.IsNullOrWhiteSpace(info.UserName) && !String.IsNullOrWhiteSpace(info.DisplayName) && !String.IsNullOrWhiteSpace(info.OwnNumber)
                            && !String.IsNullOrWhiteSpace(info.Status) && !String.IsNullOrWhiteSpace(info.SerialNum) && !String.IsNullOrWhiteSpace(info.ComId))
                            return mgr.AddUser(info, resourceInfo);
                        throw new Exception(CodeHelper.UnableToAddUser);
                    }

                    // throw exception stating token is invalid
                    throw new Exception(CodeHelper.InvalidToken);
                }

                throw new Exception(CodeHelper.InvalidHeader);
            }
            catch (Exception ex)
            {
                //HttpContext.Current.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                //return ex.Message;
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
            }
        }
Example #3
0
        /// <summary>
        /// Add Set of Contacts
        /// </summary>
        /// <param name="userIdf"></param>
        /// <param name="lstContacts"></param>
        /// <returns></returns>
        public List<ContactInfo> AddContacts(Guid userIdf, List<ContactInfo> lstContacts)
        {
            try
            {
                DataTable dtContacts = new DataTable("ContactType");
                dtContacts.Columns.Add("ContactUserIdf", typeof(Guid));
                dtContacts.Columns.Add("Name");
                dtContacts.Columns.Add("Number");
                dtContacts.Columns.Add("TerritoryId");

                TerritoryManager mgr = new TerritoryManager();

                var lstTerritory = mgr.GetTerritoryList();

                Tuple<int, string> territory = mgr.GetTerritoryIdByUserIdf(userIdf);

                lstContacts = new HeyVoteUtil().ValidatePhoneNumbers(lstContacts, territory.Item2, lstTerritory);

                lstContacts.ForEach(x =>
                {
                    dtContacts.Rows.Add(Guid.Empty, x.Name, x.Number, x.TerritoryId);
                });

                using (SqlDataAdapter adapter = new SqlDataAdapter("[contact].[SyncContacts]", AppConfigManager.ConnectionString))
                {
                    adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                    SqlParameter parameter = new SqlParameter();
                    parameter.ParameterName = "@syncContacts";
                    parameter.SqlDbType = System.Data.SqlDbType.Structured;
                    parameter.Value = dtContacts;
                    adapter.SelectCommand.Parameters.Add(parameter);
                    adapter.SelectCommand.Parameters.AddWithValue("@UserIdf", userIdf);
                    adapter.SelectCommand.Connection.Open();
                    int result = adapter.SelectCommand.ExecuteNonQuery();
                    adapter.SelectCommand.Connection.Close();
                    return GetContactList(userIdf, true, false, false, false);
                }

            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                throw new Exception(CodeHelper.UnableToAddContact);
            }
        }