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); } }
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); } }