Ejemplo n.º 1
0
        public static GenericError UserContextLoad(
            System.Web.Http.Controllers.HttpActionContext actionContext = null,
            string token    = "",
            TokenType type  = TokenType.None,
            string deviceId = "",
            int communityId = 0,
            int languageId  = 1,
            Int64 linkId    = 0
            )
        {
            LastError = GenericError.None;

            if (String.IsNullOrEmpty(token) && actionContext != null)
            {
                token = Helper.ContextHelper.TokenGet(actionContext);
            }

            if (type == TokenType.None && actionContext != null)
            {
                type = Helper.ContextHelper.TokenTypeGet(actionContext);
            }

            if (String.IsNullOrEmpty(deviceId) && actionContext != null)
            {
                deviceId = Helper.ContextHelper.DeviceIdGet(actionContext);
            }


            if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(deviceId))
            {
                LastError = GenericError.TokenInvalid;
                return(LastError);
            }

            if (communityId <= 0)
            {
                communityId = CommunityIdGet(actionContext);
            }

            if (linkId <= 0)
            {
                linkId = LinkIdGet(actionContext);
            }

            iDataContext dataContext = Helper.ContextHelper.DataContext;


            Adevico.APIconnection.Core.Business.CoreAPIService coreApiService =
                new Adevico.APIconnection.Core.Business.CoreAPIService(dataContext);

            iPerson currentUser = coreApiService.PersonGetFromToken(token, deviceId, type);

            iUserContext userContext;

            if (languageId <= 0)
            {
                languageId = currentUser.LanguageID;
            }

            Language lang = coreApiService.LanguageGet(languageId);

            int workingCommunityId = coreApiService.CommunityIdGetFromLink(linkId);

            if (currentUser != null && currentUser.Id > 0)
            {
                userContext = new UserContext
                {
                    CurrentCommunityID             = communityId,
                    CurrentCommunityOrganizationID = 0,
                    CurrentUser        = currentUser,
                    IpAddress          = "--", //Todo
                    ProxyIpAddress     = "--", //Todo
                    isAnonymous        = false,
                    Language           = lang,
                    WorkingCommunityID = workingCommunityId
                };
            }
            else
            {
                userContext = new UserContext();
                LastError   = GenericError.TokenExpired;
                //return LastError;
            }

            //API Context
            APIContext = new ApiContext();
            APIContext.CurrentLinkId = linkId;


            Helper.ContextHelper.UserContext = userContext;

            return(LastError);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Save the newly created member
 /// </summary>
 /// <param name="Member">Object of class implementing iPerson, containg member data</param>
 public void AddMember(iPerson Member)
 {
     MockDataStorage.Members.Add(Member);
 }