Exemple #1
0
        public async Task <ActionResult> New(CommunityInputViewModel communityJson)
        {
            if (CurrentUserId == 0)
            {
                await TryAuthenticateFromHttpContext();
            }

            if (ModelState.IsValid)
            {
                var communityDetails = new CommunityDetails();
                Mapper.Map(communityJson, communityDetails);

                // Set thumbnail properties
                communityDetails.Thumbnail = new FileDetail()
                {
                    AzureID = communityJson.ThumbnailID
                };
                communityDetails.CreatedByID = CurrentUserId;
                communityJson.ID             = communityDetails.ID = _communityService.CreateCommunity(communityDetails);

                // Send Notification Mail
                _notificationService.NotifyNewEntityRequest(communityDetails, HttpContext.Request.Url.GetServerLink());

                return(new JsonResult {
                    Data = new { ID = communityDetails.ID }
                });
            }

            // In case of any validation error stay in the same page.
            return(new JsonResult {
                Data = false
            });
        }
Exemple #2
0
        /// <summary>
        /// Creates default user community.
        /// </summary>
        /// <param name="userId">User identity.</param>
        private void CreateDefaultUserCommunity(long userId)
        {
            // This will used as the default community when user is uploading a new content.
            // This community will need to have the following details:
            var communityDetails = new CommunityDetails();

            // 1. This community type should be User
            communityDetails.CommunityType = CommunityTypes.User;

            // 2. CreatedBy will be the new USER.
            communityDetails.CreatedByID = userId;

            // 3. This community is not featured.
            communityDetails.IsFeatured = false;

            // 4. Name should be NONE.
            communityDetails.Name = Resources.UserCommunityName;

            // 5. Access type should be private.
            communityDetails.AccessTypeID = (int)AccessType.Private;

            // 6. Set the category ID of general interest. We need to set the Category ID as it is a foreign key and cannot be null.
            communityDetails.CategoryID = (int)CategoryType.GeneralInterest;

            // 7. Create the community
            _communityService.CreateCommunity(communityDetails);
        }
Exemple #3
0
        protected async Task <LiveLoginResult> TryAuthenticateFromHttpContext(ICommunityService communityService, INotificationService notificationService)
        {
            var svc    = new LiveIdAuth();
            var result = await svc.Authenticate();

            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                var client = new LiveConnectClient(result.Session);
                SessionWrapper.Set("LiveConnectClient", client);
                SessionWrapper.Set("LiveConnectResult", result);
                SessionWrapper.Set("LiveAuthSvc", svc);

                var getResult = await client.GetAsync("me");

                var jsonResult     = getResult.Result as dynamic;
                var profileDetails = ProfileService.GetProfile(jsonResult.id);
                if (profileDetails == null)
                {
                    profileDetails = new ProfileDetails(jsonResult);
                    // While creating the user, IsSubscribed to be true always.
                    profileDetails.IsSubscribed = true;

                    // When creating the user, by default the user type will be of regular.
                    profileDetails.UserType = UserTypes.Regular;
                    profileDetails.ID       = ProfileService.CreateProfile(profileDetails);

                    // This will used as the default community when user is uploading a new content.
                    // This community will need to have the following details:
                    var communityDetails = new CommunityDetails
                    {
                        CommunityType = CommunityTypes.User,         // 1. This community type should be User
                        CreatedByID   = profileDetails.ID,           // 2. CreatedBy will be the new USER.
                        IsFeatured    = false,                       // 3. This community is not featured.
                        Name          = Resources.UserCommunityName, // 4. Name should be NONE.
                        AccessTypeID  = (int)AccessType.Private,     // 5. Access type should be private.
                        CategoryID    = (int)CategoryType.GeneralInterest
                                                                     // 6. Set the category ID of general interest. We need to set the Category ID as it is a foreign key and cannot be null.
                    };

                    // 7. Create the community
                    communityService.CreateCommunity(communityDetails);

                    // Send New user notification.
                    notificationService.NotifyNewEntityRequest(profileDetails,
                                                               HttpContext.Request.Url.GetServerLink());
                }

                SessionWrapper.Set <long>("CurrentUserID", profileDetails.ID);
                SessionWrapper.Set <string>("CurrentUserProfileName",
                                            profileDetails.FirstName + " " + profileDetails.LastName);
                SessionWrapper.Set("ProfileDetails", profileDetails);
                SessionWrapper.Set("AuthenticationToken", result.Session.AuthenticationToken);
            }
            return(result);
        }
        public async Task <IHttpActionResult> CreateCommunity([FromBody] CreateCommunityModel createCommunityModel)
        {
            if (ModelState.IsValid)
            {
                var communityId = await _communityService.CreateCommunity(createCommunityModel).ConfigureAwait(false);

                if (communityId != -1)
                {
                    return(Created("", $"{Request.RequestUri.AbsoluteUri}/{communityId}"));
                }
                return(BadRequest("Something went wrong !"));
            }
            return(BadRequest("Something went wrong !"));
        }
        public async Task <bool> RegisterUser()
        {
            var profileDetails = await ValidateAuthentication();

            if (profileDetails == null)
            {
                var     svc        = new LiveIdAuth();
                dynamic jsonResult = svc.GetMeInfo(System.Web.HttpContext.Current.Request.Headers["LiveUserToken"]);
                profileDetails = new ProfileDetails(jsonResult);
                // While creating the user, IsSubscribed to be true always.
                profileDetails.IsSubscribed = true;

                // When creating the user, by default the user type will be of regular.
                profileDetails.UserType = UserTypes.Regular;
                profileDetails.ID       = ProfileService.CreateProfile(profileDetails);

                // This will used as the default community when user is uploading a new content.
                // This community will need to have the following details:
                var communityDetails = new CommunityDetails
                {
                    CommunityType = CommunityTypes.User,              // 1. This community type should be User
                    CreatedByID   = profileDetails.ID,                // 2. CreatedBy will be the new USER.
                    IsFeatured    = false,                            // 3. This community is not featured.
                    Name          = Resources.UserCommunityName,      // 4. Name should be NONE.
                    AccessTypeID  = (int)AccessType.Private,          // 5. Access type should be private.
                    CategoryID    = (int)CategoryType.GeneralInterest // 6. Set the category ID of general interest. We need to set the Category ID as it is a foreign key and cannot be null.
                };

                // 7. Create the community
                _communityService.CreateCommunity(communityDetails);

                // Send New user notification.
                _notificationService.NotifyNewEntityRequest(profileDetails,
                                                            HttpContext.Request.Url.GetServerLink());
            }
            else
            {
                throw new WebFaultException <string>("User already registered", HttpStatusCode.BadRequest);
            }
            return(true);
        }
Exemple #6
0
        protected async Task<LiveLoginResult> TryAuthenticateFromHttpContext(ICommunityService communityService, INotificationService notificationService)
        {
            var svc = new LiveIdAuth();
            var result = await svc.Authenticate();
            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                var client = new LiveConnectClient(result.Session);
                SessionWrapper.Set("LiveConnectClient", client);
                SessionWrapper.Set("LiveConnectResult", result);
                SessionWrapper.Set("LiveAuthSvc", svc);

                var getResult = await client.GetAsync("me");
                var jsonResult = getResult.Result as dynamic;
                var profileDetails = ProfileService.GetProfile(jsonResult.id);
                if (profileDetails == null)
                {
                    profileDetails = new ProfileDetails(jsonResult);
                    // While creating the user, IsSubscribed to be true always.
                    profileDetails.IsSubscribed = true;

                    // When creating the user, by default the user type will be of regular. 
                    profileDetails.UserType = UserTypes.Regular;
                    profileDetails.ID = ProfileService.CreateProfile(profileDetails);

                    // This will used as the default community when user is uploading a new content.
                    // This community will need to have the following details:
                    var communityDetails = new CommunityDetails
                    {
                        CommunityType = CommunityTypes.User, // 1. This community type should be User
                        CreatedByID = profileDetails.ID, // 2. CreatedBy will be the new USER.
                        IsFeatured = false, // 3. This community is not featured.
                        Name = Resources.UserCommunityName, // 4. Name should be NONE.
                        AccessTypeID = (int) AccessType.Private, // 5. Access type should be private.
                        CategoryID = (int) CategoryType.GeneralInterest
                        // 6. Set the category ID of general interest. We need to set the Category ID as it is a foreign key and cannot be null.
                    };

                    // 7. Create the community
                    communityService.CreateCommunity(communityDetails);

                    // Send New user notification.
                    notificationService.NotifyNewEntityRequest(profileDetails,
                        HttpContext.Request.Url.GetServerLink());
                }

                SessionWrapper.Set<long>("CurrentUserID", profileDetails.ID);
                SessionWrapper.Set<string>("CurrentUserProfileName",
                    profileDetails.FirstName + " " + profileDetails.LastName);
                SessionWrapper.Set("ProfileDetails", profileDetails);
                SessionWrapper.Set("AuthenticationToken", result.Session.AuthenticationToken);
            }
            return result;
        }