public StudentDashboardViewModel(UserBusinessObject user)
 {
     User = user;
     InitializeContainers();
     ResolveContainers();
     InitializeServices();
     InitializeProperties();
 }
Esempio n. 2
0
        public override async Task OnConnected()
        {
            var applicationIdString = Context.QueryString[QUERY_STRING_APPLICATION_KEY];
            var externalUserToken = Context.QueryString[QUERY_STRING_TOKEN_KEY];
            var externalUserIPAddress = GetIPAddress();
            int applicationId;
            string checkUserIdUrl;

            if (!Int32.TryParse(applicationIdString, out applicationId))
                return;

            using (var bo = new ApplicationBusinessObject())
            {
                var application = bo.GetById(applicationId);
                if (application == null)
                    return;

                checkUserIdUrl = application.CheckUserIdUrl;
            }

            var externalUserId = await GetExternalUserId(checkUserIdUrl, externalUserToken, externalUserIPAddress);

            if (String.IsNullOrWhiteSpace(externalUserId))
                return;

            // Check if user exists in our database
            using (var bo = new UserBusinessObject())
            {
                var user = bo.GetList(x => x.ApplicationId == applicationId && x.ExternalUserId == externalUserId).FirstOrDefault();
                if (user == null) return;
            }

            GroupName = applicationId + externalUserId;


            await Groups.Add(Context.ConnectionId, GroupName);

            Clients.Caller.AuthenticationSuccess(applicationId, externalUserId);
            Clients.Group(GroupName).UserConnected(externalUserId);

            await base.OnConnected();
        }
Esempio n. 3
0
        List<Tuple<int?, string>> GetUserInfos(int applicationId, List<string> externalUserIds, int providerId)
        {
            var result = new List<Tuple<int?, string>>();

            foreach (var item in externalUserIds)
            {
                using (var bo = new UserBusinessObject())
                {
                    var user = bo.GetByExternalUserId(applicationId, item);
                    if (user == null)
                        continue;

                    var to = GetToByProvider(user, providerId);
                    if (String.IsNullOrEmpty(to))
                        continue;

                    result.Add(new Tuple<int?, string>(user.Id, to));
                }
            }

            return result;
        }
Esempio n. 4
0
        public APIResult UnsubscribeEvent(SubscribeUserModel model)
        {
            try
            {
                if (model == null)
                    throw new Exception("Please pass model");

                using (var bo = new ApplicationBusinessObject())
                {
                    if (!bo.Check(model.ApplicationId, model.ApplicationSecretKey))
                        throw new Exception("Invalid application credentials");
                }

                int eventId;
                using (var bo = new EventBusinessObject())
                {
                    var ev = bo.GetByKey(model.ApplicationId, model.EventKey);
                    if (ev == null)
                        throw new Exception("Event not found");

                    eventId = ev.Id;
                }

                int userId;
                using (var bo = new UserBusinessObject())
                {
                    var user = bo.GetByExternalUserId(model.ApplicationId, model.ExternalUserId);
                    if (user == null)
                        throw new Exception("User not found");

                    userId = user.Id;
                }

                Provider provider;
                using (var bo = new ProviderBusinessObject())
                {
                    provider = bo.GetByKey(model.ProviderKey);
                    if (provider == null)
                        throw new Exception("Provider not found");
                }

                var subscription = new Subscription
                {
                    EventId = eventId,
                    UserId = userId,
                    ProviderId = provider.Id
                };

                using (var bo = new SubscriptionBusinessObject())
                {
                    bo.Unsubscribe(subscription);
                }

            }
            catch (Exception ex)
            {
                return new APIResult(ex.Message, ex.ToString());
            }

            return new APIResult();
        }
Esempio n. 5
0
        public APIResult SaveUsers(SaveUsersModel model)
        {
            try
            {
                if (model == null)
                    throw new Exception("Please pass model");

                using (var bo = new ApplicationBusinessObject())
                {
                    if (!bo.Check(model.ApplicationId, model.ApplicationSecretKey))
                        throw new Exception("Invalid application credentials");
                }

                foreach (var item in model.Users)
                {
                    var user = new User
                    {
                        ApplicationId = model.ApplicationId,
                        ExternalUserId = item.ExternalUserId,
                        FirstName = item.FirstName,
                        FullName = item.FullName,
                        Email = item.Email,
                        MobileNumber = item.MobileNumber
                    };

                    using (var bo = new UserBusinessObject())
                    {
                        bo.Save(user);
                    }
                }

            }
            catch (Exception ex)
            {
                return new APIResult(ex.Message, ex.ToString());
            }

            return new APIResult();
        }