Exemplo n.º 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
            });
        }
Exemplo n.º 2
0
        public async Task <JsonResult> Edit(CommunityInputViewModel community)
        {
            if (CurrentUserId == 0)
            {
                await TryAuthenticateFromHttpContext();
            }
            try
            {
                var communityDetails = new CommunityDetails();
                Mapper.Map(community, communityDetails);

                // Set thumbnail properties
                communityDetails.Thumbnail = new FileDetail {
                    AzureID = community.ThumbnailID
                };

                if (CurrentUserId == 0)
                {
                    return(Json("error: user not logged in"));
                }
                _communityService.UpdateCommunity(communityDetails, CurrentUserId);
                return(Json(new { id = community.ID }));
            }
            catch (Exception)
            {
            }

            return(Json("error: community not saved"));
        }
Exemplo n.º 3
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);
        }
 /// <summary>
 /// Notify the user about the new community.
 /// </summary>
 /// <param name="communityDetails">Community details</param>
 /// <param name="server">Server details.</param>
 public void NotifyNewEntityRequest(CommunityDetails communityDetails, string server)
 {
     if (Constants.CanSendNewEntityMail)
     {
         SendNewCommunityMail(communityDetails, server);
     }
 }
Exemplo n.º 5
0
        private async Task <ProfileDetails> InitUserProfile(string liveId, string accessToken)
        {
            if (string.IsNullOrEmpty(liveId))
            {
                return(null);
            }
            var profileDetails = ProfileService.GetProfile(liveId);

            if (profileDetails == null)
            {
                if (string.IsNullOrEmpty(accessToken))
                {
                    return(null);
                }
                var svc = new LiveIdAuth();

                var getResult = await svc.GetMeInfo(accessToken);

                var jsonResult = getResult;
                profileDetails = new ProfileDetails(jsonResult)
                {
                    IsSubscribed = true,
                    UserType     = UserTypes.Regular
                };
                // While creating the user, IsSubscribed to be true always.

                // When creating the user, by default the user type will be of 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.
                };

                var communityService    = DependencyResolver.Current.GetService(typeof(ICommunityService)) as ICommunityService;
                var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService;
                // 7. Create the community
                communityService.CreateCommunity(communityDetails);

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

            SessionWrapper.Set("CurrentUserID", profileDetails.ID);
            SessionWrapper.Set("CurrentUserProfileName",
                               profileDetails.FirstName + " " + profileDetails.LastName);
            SessionWrapper.Set("ProfileDetails", profileDetails);

            return(profileDetails);
        }
Exemplo n.º 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);
        }
Exemplo n.º 7
0
        public async Task AddFarmerAsCommunity_InvalidUserDetails_BadFlow()
        {
            CommunityDetails community = new CommunityDetails {
                CommunityName = "LocalCommunity"
            };
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId  = 1234,
                User      = FarmerTestData(),
                Community = community
            };

            _farmerRepositoryMock.Setup(b => b.AddFarmerRegistrationDetails(It.IsAny <FarmerDetails>())).ThrowsAsync(new DataNotSavedException("Duplication"));
            await Assert.ThrowsExceptionAsync <DataNotSavedException>(async() => await _farmerServices.AddFarmerRegistrationDetails(farmer));
        }
        /// <summary>
        /// Populates the EntityViewModel object's properties from the given CommunityDetails object's properties.
        /// </summary>
        /// <param name="thisObject">Current entity view model on which the extension method is called</param>
        /// <param name="communityDetails">CommunityDetails model from which values to be read</param>
        /// <returns>Values populated EntityViewModel instance</returns>
        public static EntityViewModel SetValuesFrom(this EntityViewModel thisObject, CommunityDetails communityDetails)
        {
            if (communityDetails != null)
            {
                if (thisObject == null)
                {
                    thisObject = new EntityViewModel();
                }

                thisObject.Entity = communityDetails.CommunityType == CommunityTypes.Community ? EntityType.Community : EntityType.Folder;

                // Populate the base values using the EntityViewModel's SetValuesFrom method which take EntityDetails as input.
                thisObject.SetValuesFrom(communityDetails as EntityDetails);
            }

            return(thisObject);
        }
Exemplo n.º 9
0
        public async Task AddFarmerAsCommunity_UniqueDetails_HappyFlow()
        {
            CommunityDetails community = new CommunityDetails {
                CommunityName = "LocalCommunity"
            };
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId  = 1234,
                User      = FarmerTestData(),
                Community = community
            };

            _farmerRepositoryMock.Setup(f => f.AddFarmerRegistrationDetails(It.IsAny <FarmerDetails>())).ReturnsAsync("Successfull");
            var testResult = await _farmerServices.AddFarmerRegistrationDetails(farmer);

            Assert.AreEqual("Successfull", testResult);
        }
Exemplo n.º 10
0
        private FarmerDetails FarmersData()
        {
            CommunityDetails community = new CommunityDetails {
                CommunityName = "LocalCommunity"
            };
            FarmerDetails farmerDetails = new FarmerDetails
            {
                FarmerId          = 1,
                UserId            = 1,
                IsApproved        = true,
                IsAccountDisabled = false,
                CommunityId       = 1,

                Community = community,
                User      = BuyersData()
            };

            return(farmerDetails);
        }
        private void SendNewCommunityMail(CommunityDetails communityDetails, string server)
        {
            try
            {
                // Send Mail.
                var request = new NewEntityRequest();
                request.EntityType = communityDetails.CommunityType == CommunityTypes.Community ? EntityType.Community : EntityType.Folder;
                request.EntityID   = communityDetails.ID;
                request.EntityName = communityDetails.Name;
                request.EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}Community/Index/{1}", server, communityDetails.ID);
                request.UserID     = communityDetails.CreatedByID;
                request.UserLink   = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", server, communityDetails.CreatedByID);

                SendMail(request);
            }
            catch (Exception)
            {
                // Ignore all exceptions.
            }
        }
        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);
        }
Exemplo n.º 13
0
        public async Task AddFarmerAsCommunity_InvalidCommunityName_BadFlow()
        {
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId  = 1234,
                User      = FarmerTestData(),
                Community = new CommunityDetails()
                {
                    CommunityName = "localcommunity"
                }
            };
            CommunityDetails communityDetails = new CommunityDetails
            {
                CommunityName = "localcommunity"
            };

            _orchard1Context.Users.Add(FarmerTestData2());
            _orchard1Context.CommunityDetails.Add(communityDetails);
            _orchard1Context.SaveChanges();

            await Assert.ThrowsExceptionAsync <DataNotSavedException>(async() => await farmerRepository.AddFarmerRegistrationDetails(farmer));
        }
Exemplo n.º 14
0
        public IEnumerable <CommunityDetails> GetCommunities(long userId, PageDetails pageDetails, bool onlyPublic)
        {
            this.CheckNotNull(() => new { userID = userId, pageDetails });

            IList <CommunityDetails> userCommunities = new List <CommunityDetails>();

            Func <CommunitiesView, object> orderBy = c => c.LastUpdatedDatetime;

            // Get all the community ids to which user is given role of contributor or higher.
            var userCommunityIds = _userRepository.GetUserCommunitiesForRole(userId, UserRole.Contributor, onlyPublic);

            // Get only the communities for the current page.
            userCommunityIds = userCommunityIds.Skip((pageDetails.CurrentPage - 1) * pageDetails.ItemsPerPage).Take(pageDetails.ItemsPerPage);

            Expression <Func <CommunitiesView, bool> > condition = c => userCommunityIds.Contains(c.CommunityID);

            foreach (var community in _communitiesViewRepository.GetItems(condition, orderBy, true))
            {
                CommunityDetails communityDetails;
                if (onlyPublic)
                {
                    // In case of only public, user is looking at somebody else profile and so just send the user role as Visitor.
                    communityDetails = new CommunityDetails(Permission.Visitor);
                }
                else
                {
                    var userRole = _userRepository.GetUserRole(userId, community.CommunityID);
                    communityDetails = new CommunityDetails(userRole.GetPermission());
                }

                Mapper.Map(community, communityDetails);
                userCommunities.Add(communityDetails);
            }

            return(userCommunities);
        }
        private ContentDetails GetContentDetail(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity)
        {
            var content = new ContentDetails();

            var fileDetail = UpdateFileDetails(filename, fileContent);

            content.ContentData = fileDetail;
            content.CreatedByID = profileDetails.ID;

            // By Default the access type will be private.
            content.AccessTypeID = (int)AccessType.Public;

            // Get the Category/Tags from Parent.
            content.ParentID   = parentCommunity.ID;
            content.ParentType = parentCommunity.CommunityType;
            content.CategoryID = parentCommunity.CategoryID;

            return(content);
        }
        private long CreateCollection(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity)
        {
            // Get name/ tags/ category from Tour.
            var            collectionDoc = new XmlDocument();
            ContentDetails content       = null;

            // NetworkStream is not Seek able. Need to load into memory stream so that it can be sought
            using (Stream writablefileContent = new MemoryStream())
            {
                fileContent.CopyTo(writablefileContent);
                writablefileContent.Position = 0;
                content = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity);
                writablefileContent.Seek(0, SeekOrigin.Begin);
                collectionDoc = collectionDoc.SetXmlFromWtml(writablefileContent);
            }

            if (collectionDoc != null)
            {
                content.Name = collectionDoc.GetAttributeValue("Folder", "Name");
            }

            var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService;
            var contentId      = content.ID = contentService.CreateContent(content);

            if (contentId > 0)
            {
                var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService;
                notificationService.NotifyNewEntityRequest(content, BaseUri() + "/");
            }

            return(contentId);
        }
        private long CreateContent(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity)
        {
            ContentDetails content = null;

            // No need to get into a memory stream as the stream is sent as is and need not be loaded
            using (Stream writablefileContent = new MemoryStream())
            {
                fileContent.CopyTo(writablefileContent);
                writablefileContent.Position = 0;
                content      = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity);
                content.Name = Path.GetFileNameWithoutExtension(filename);
            }

            var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService;
            var contentId      = content.ID = contentService.CreateContent(content);

            if (contentId > 0)
            {
                var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService;
                notificationService.NotifyNewEntityRequest(content, BaseUri() + "/");
            }

            return(contentId);
        }
        private long CreateTour(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity)
        {
            var            tourDoc = new XmlDocument();
            ContentDetails content = null;

            // NetworkStream is not Seek able. Need to load into memory stream so that it can be sought
            using (Stream writablefileContent = new MemoryStream())
            {
                fileContent.CopyTo(writablefileContent);
                writablefileContent.Position = 0;
                content = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity);
                writablefileContent.Position = 0;
                tourDoc = tourDoc.SetXmlFromTour(writablefileContent);
            }

            if (tourDoc != null)
            {
                // Note that the spelling of Description is wrong because that's how WWT generates the WTT file.
                content.Name          = tourDoc.GetAttributeValue("Tour", "Title");
                content.Description   = tourDoc.GetAttributeValue("Tour", "Descirption");
                content.DistributedBy = tourDoc.GetAttributeValue("Tour", "Author");
                content.TourLength    = tourDoc.GetAttributeValue("Tour", "RunTime");
            }

            var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService;
            var contentId      = content.ID = contentService.CreateContent(content);

            if (contentId > 0)
            {
                var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService;
                notificationService.NotifyNewEntityRequest(content, BaseUri() + "/");
            }

            return(contentId);
        }
Exemplo n.º 19
0
        public async Task <string> AddFarmerRegistrationDetails(FarmerDetails farmer)
        {
            Users userDataForEmailCheck = await _Orchard1Context.Users.FirstOrDefaultAsync(user => user.Email == farmer.User.Email);

            Users userDataForMobileNumberCheck = await _Orchard1Context.Users.FirstOrDefaultAsync(userData => userData.PhoneNumber == farmer.User.PhoneNumber);

            if (userDataForEmailCheck == null && userDataForMobileNumberCheck == null)
            {
                FarmerDetails farmerDetails = await _Orchard1Context.FarmerDetails.FirstOrDefaultAsync(farmerData => farmerData.FarmerId == farmer.FarmerId);

                if (farmer.Community == null && farmerDetails == null)
                {
                    try
                    {
                        Users user = farmer.User;
                        await _Orchard1Context.AddAsync(user);

                        farmer.UserId = user.UserId;
                        await _Orchard1Context.AddAsync(farmer);
                    }
                    catch (SqlException ex)
                    {
                        throw new DataNotSavedException("Data not saved", ex);
                    }
                }
                else if (farmer.Community != null && farmerDetails == null)
                {
                    CommunityDetails communityDetails = await _Orchard1Context.CommunityDetails.FirstOrDefaultAsync(community => community.CommunityName == farmer.Community.CommunityName);

                    if (communityDetails == null)
                    {
                        try
                        {
                            Users userData = farmer.User;
                            await _Orchard1Context.AddAsync(userData);

                            CommunityDetails communityData = farmer.Community;
                            await _Orchard1Context.AddAsync(communityData);

                            farmer.UserId      = userData.UserId;
                            farmer.CommunityId = communityData.CommunityId;
                            await _Orchard1Context.AddAsync(farmer);
                        }
                        catch (SqlException ex)
                        {
                            throw new DataNotSavedException("Data not saved", ex);
                        }
                    }
                    else
                    {
                        int isFarmerAdded = await _Orchard1Context.SaveChangesAsync();

                        if (isFarmerAdded == 0)
                        {
                            throw new DataNotSavedException("Community Name Already Exists");
                        }
                    }
                }
                else if (farmerDetails != null)
                {
                    int isFarmerAdded = await _Orchard1Context.SaveChangesAsync();

                    if (isFarmerAdded == 0)
                    {
                        throw new DataNotSavedException("FarmerId already exists");
                    }
                }
            }
            else
            {
                int isFarmerAdded = await _Orchard1Context.SaveChangesAsync();

                if (isFarmerAdded == 0)
                {
                    throw new DataNotSavedException("Duplication");
                }
            }
            int isDataAdded = await _Orchard1Context.SaveChangesAsync();

            if (isDataAdded > 0)
            {
                return("Successfull");
            }
            else
            {
                throw new DataNotSavedException("Duplication");
            }
        }