Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }