Exemplo n.º 1
0
 public static void AddDataOnLinkDetails(LinkDetailEntity item)
 {
     try
     {
         using (FacilitiesEntities _dbContext = new FacilitiesEntities())
         {
             var data = _dbContext.CGSLinkDetails.Where(x => x.CGSLinkHeader == item.CGSLinkHeader).ToList();
             if (data != null)
             {
                 foreach (var ss in item.Value)
                 {
                     var        dd = data.FirstOrDefault(r => r.ColumnHeader == ss.Key);
                     LinkDetail LD = new LinkDetail();
                     LD.LinkDetailId   = Guid.NewGuid();
                     LD.CGSLinkHeader  = item.CGSLinkHeader;
                     LD.CGSLinkDetails = dd.CGSLinkDetailId;
                     LD.LinkHeader     = item.LinkHeader;
                     LD.Value          = ss.value;
                     _dbContext.LinkDetails.Add(LD);
                     _dbContext.SaveChanges();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw (ex);
     }
 }
 /// <summary>
 /// Populates the Content object's properties from the given LinkDetail object's properties.
 /// </summary>
 /// <param name="thisObject">Current Content instance on which the extension method is called</param>
 /// <param name="linkDetails">LinkDetail model from which values to be read</param>
 public static void SetValuesFrom(this Content thisObject, LinkDetail linkDetails)
 {
     if (linkDetails != null && thisObject != null)
     {
         thisObject.ContentUrl = linkDetails.ContentUrl;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Populates the FileDetail object's properties from the given Content object's properties.
        /// </summary>
        /// <param name="thisObject">Current FileDetail instance on which the extension method is called</param>
        /// <param name="content">Content model from which values to be read</param>
        public static DataDetail SetValuesFrom(this DataDetail thisObject, Content content)
        {
            if (content != null)
            {
                // Set Content Type.
                ContentTypes type = content.TypeID.ToEnum <int, ContentTypes>(ContentTypes.Generic);

                if (type == ContentTypes.Link)
                {
                    thisObject = new LinkDetail(content.ContentUrl, content.ContentID);
                }
                else
                {
                    var fileDetail = new FileDetail();
                    fileDetail.SetValuesFrom(content);
                    thisObject = fileDetail;
                }

                thisObject.Name        = content.Filename;
                thisObject.ContentType = type;
            }

            return(thisObject);
        }
Exemplo n.º 4
0
        public static void RegisterServiceAutoMappers()
        {
            // Used by CommentService
            Mapper.CreateMap <CommentDetails, CommunityComments>()
            .ForMember(target => target.CommunityID, options => options.MapFrom(source => source.ParentID))
            .ForMember(target => target.CommunityCommentsID, options => options.MapFrom(source => source.CommentID));

            Mapper.CreateMap <CommentDetails, ContentComments>()
            .ForMember(target => target.ContentID, options => options.MapFrom(source => source.ParentID))
            .ForMember(target => target.ContentCommentsID, options => options.MapFrom(source => source.CommentID));

            Mapper.CreateMap <CommunityComments, CommentDetails>()
            .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.CommentedBy, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName))
            .ForMember(target => target.CommentedByPictureID, options => options.MapFrom(source => source.User.PictureID))
            .ForMember(target => target.CommentID, options => options.MapFrom(source => source.CommunityCommentsID));

            Mapper.CreateMap <ContentComments, CommentDetails>()
            .ForMember(target => target.ParentID, options => options.MapFrom(source => source.ContentID))
            .ForMember(target => target.CommentedDatetime, options => options.MapFrom(source => source.CommentDatetime))
            .ForMember(target => target.CommentedBy, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName))
            .ForMember(target => target.CommentedByPictureID, options => options.MapFrom(source => source.User.PictureID))
            .ForMember(target => target.CommentID, options => options.MapFrom(source => source.ContentCommentsID));

            // Used by CommunityService
            Mapper.CreateMap <CommunityDetails, Community>()
            .ForMember(target => target.CommunityTypeID, options => options.MapFrom(source => (int)source.CommunityType))
            .ForMember(target => target.CommunityType, options => options.Ignore())
            .ForMember(target => target.ThumbnailID, options => options.Ignore())
            .ForMember(target => target.CommunityID, options => options.Ignore());

            // Used by ContentService
            Mapper.CreateMap <ContentDetails, Content>()
            .ForMember(target => target.Title, options => options.MapFrom(source => source.Name));

            Mapper.CreateMap <Content, DownloadDetails>();

            Mapper.CreateMap <StaticContent, StaticContentDetails>();

            // Used by EntityService
            Mapper.CreateMap <TopCategoryEntities, ContentDetails>()
            .ForMember(target => target.Name, options => options.MapFrom(source => source.Title))
            .ForMember(target => target.ID, options => options.MapFrom(source => source.ID))
            .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.ParentName, options => options.MapFrom(source => source.CommunityName))
            .ForMember(target => target.Tags, options => options.Condition(source => !source.IsSourceValueNull))
            .ForMember(target => target.ParentType, options => options.MapFrom(source => source.CommunityTypeID.ToEnum <int?, CommunityTypes>(CommunityTypes.None)));

            Mapper.CreateMap <TopCategoryEntities, EntityDetails>()
            .ForMember(target => target.Tags, options => options.Condition(source => !source.IsSourceValueNull))
            .ForMember(target => target.ID, options => options.MapFrom(source => source.ID))
            .ForMember(target => target.Name, options => options.MapFrom(source => source.Title));

            Mapper.CreateMap <Community, CommunityDetails>()
            .ForMember(target => target.ID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.CategoryID, options => options.MapFrom(source => (int)source.Category.CategoryID))
            .ForMember(target => target.AccessTypeID, options => options.MapFrom(source => (int)source.AccessType.AccessTypeID))
            .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType.Name))
            .ForMember(target => target.CommunityType, options => options.MapFrom(source => source.CommunityTypeID))
            .ForMember(target => target.LastUpdatedDatetime, options => options.MapFrom(source => source.ModifiedDatetime));

            // Used by ProfileService
            Mapper.CreateMap <ProfileDetails, User>()
            .ForMember(target => target.LiveID, options => options.MapFrom(source => source.PUID))
            .ForMember(target => target.UserID, options => options.MapFrom(source => source.ID))
            .ForMember(target => target.Email, options => options.MapFrom(source => source.Email.FixEmailAddress()))
            .ForMember(target => target.UserTypeID, options => options.MapFrom(source => (int?)source.UserType))
            .ForMember(target => target.UserType, options => options.Ignore());

            Mapper.CreateMap <User, ProfileDetails>()
            .ForMember(target => target.PUID, options => options.MapFrom(source => source.LiveID))
            .ForMember(target => target.ID, options => options.MapFrom(source => source.UserID))
            .ForMember(target => target.Email, options => options.MapFrom(source => source.Email.FixEmailAddress()))
            .ForMember(target => target.UserType, options => options.MapFrom(source => source.UserTypeID.HasValue ? source.UserTypeID.Value.ToEnum <int, UserTypes>(UserTypes.Regular) : UserTypes.Regular))
            .ForMember(target => target.TotalSize, options => options.MapFrom(source => source.UserType.MaxAllowedSize));

            Mapper.CreateMap <User, AdminReportProfileDetails>()
            .ForMember(target => target.PUID, options => options.MapFrom(source => source.LiveID))
            .ForMember(target => target.LastLoggedOn, options => options.MapFrom(source => source.LastLoginDatetime))
            .ForMember(target => target.UserName, options => options.MapFrom(source => source.GetFullName()))
            .ForMember(target => target.Email, options => options.MapFrom(source => source.Email.FixEmailAddress()));

            Mapper.CreateMap <UserCommunities, PermissionItem>()
            .ForMember(target => target.Name, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName))
            .ForMember(target => target.Role, options => options.MapFrom(source => (UserRole)source.RoleID))
            .ForMember(target => target.Date, options => options.MapFrom(source => source.CreatedDatetime));

            Mapper.CreateMap <PermissionRequest, PermissionItem>()
            .ForMember(target => target.Name, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName))
            .ForMember(target => target.CommunityName, options => options.MapFrom(source => source.Community.Name))
            .ForMember(target => target.Role, options => options.MapFrom(source => (UserRole)source.RoleID))
            .ForMember(target => target.Date, options => options.MapFrom(source => source.RequestedDate));

            Mapper.CreateMap <PermissionItem, PermissionRequest>()
            .ForMember(target => target.RoleID, options => options.MapFrom(source => (UserRole)source.Role))
            .ForMember(target => target.Role, options => options.Ignore());

            // Used by RatingService
            Mapper.CreateMap <RatingDetails, CommunityRatings>()
            .ForMember(target => target.CommunityID, options => options.MapFrom(source => source.ParentID));

            Mapper.CreateMap <RatingDetails, ContentRatings>()
            .ForMember(target => target.RatingByID, options => options.MapFrom(source => source.RatedByID))
            .ForMember(target => target.ContentID, options => options.MapFrom(source => source.ParentID));

            // Used by ReportEntityService
            Mapper.CreateMap <ReportEntityDetails, OffensiveCommunities>()
            .ForMember(target => target.CommunityID, options => options.MapFrom(source => source.ParentID))
            .ForMember(target => target.OffensiveTypeID, options => options.MapFrom(source => (int)source.ReportEntityType))
            .ForMember(target => target.OffensiveStatusID, options => options.MapFrom(source => (int)source.Status))
            .ForMember(target => target.Comments, options => options.MapFrom(source => source.Comment));

            Mapper.CreateMap <ReportEntityDetails, OffensiveContent>()
            .ForMember(target => target.ContentID, options => options.MapFrom(source => source.ParentID))
            .ForMember(target => target.OffensiveTypeID, options => options.MapFrom(source => (int)source.ReportEntityType))
            .ForMember(target => target.OffensiveStatusID, options => options.MapFrom(source => (int)source.Status))
            .ForMember(target => target.Comments, options => options.MapFrom(source => source.Comment));

            Mapper.CreateMap <ContentsView, ContentDetails>()
            .ForMember(target => target.ID, options => options.MapFrom(source => source.ContentID))
            .ForMember(target => target.Name, options => options.MapFrom(source => source.Title))
            .ForMember(target => target.ParentType, options => options.MapFrom(source => source.CommunityTypeID))
            .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.ParentName, options => options.MapFrom(source => source.CommunityName))
            .ForMember(target => target.Tags, options => options.MapFrom(source => (source.Tags ?? string.Empty)))
            .ForMember(target => target.SortOrder, options => options.Ignore())
            .ForMember(target => target.TourLength, options => options.MapFrom(source => source.TourRunLength))
            .ForMember(
                target => target.Thumbnail,
                options => options.MapFrom(source => new FileDetail()
            {
                AzureID = source.ThumbnailID ?? Guid.Empty
            }))
            .ForMember(
                target => target.ContentData,
                options => options.ResolveUsing(source =>
            {
                ContentTypes type = source.TypeID.ToEnum <int, ContentTypes>(ContentTypes.Generic);
                DataDetail dataDetail;

                if (type == ContentTypes.Link)
                {
                    dataDetail = new LinkDetail(source.ContentUrl, source.ContentID);
                }
                else
                {
                    var fileDetail       = new FileDetail();
                    fileDetail.ContentID = source.ContentID;
                    fileDetail.AzureID   = source.ContentAzureID;
                    dataDetail           = fileDetail;
                }

                dataDetail.Name        = source.Filename;
                dataDetail.ContentType = type;
                return(dataDetail);
            }));

            Mapper.CreateMap <AllContentsView, ContentDetails>()
            .ForMember(target => target.ID, options => options.MapFrom(source => source.ContentID))
            .ForMember(target => target.Name, options => options.MapFrom(source => source.Title))
            .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType))
            .ForMember(target => target.ParentType, options => options.MapFrom(source => source.CommunityTypeID))
            .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.ParentName, options => options.MapFrom(source => source.CommunityName))
            .ForMember(target => target.Tags, options => options.MapFrom(source => (source.Tags ?? string.Empty)))
            .ForMember(target => target.SortOrder, options => options.Ignore())
            .ForMember(
                target => target.Thumbnail,
                options => options.ResolveUsing(source =>
            {
                var thumbnailDetail     = new FileDetail();
                thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty;
                return(thumbnailDetail);
            }))
            .ForMember(
                target => target.ContentData,
                options => options.ResolveUsing(source =>
            {
                ContentTypes type = source.TypeID.ToEnum <int, ContentTypes>(ContentTypes.Generic);
                DataDetail dataDetail;

                if (type == ContentTypes.Link)
                {
                    dataDetail = new LinkDetail(source.ContentUrl, source.ContentID);
                }
                else
                {
                    var fileDetail       = new FileDetail();
                    fileDetail.ContentID = source.ContentID;
                    fileDetail.AzureID   = source.ContentAzureID;
                    dataDetail           = fileDetail;
                }

                dataDetail.Name        = source.Filename;
                dataDetail.ContentType = type;
                return(dataDetail);
            }));

            Mapper.CreateMap <FeaturedContentsView, ContentDetails>()
            .ForMember(target => target.ID, options => options.MapFrom(source => source.ContentID))
            .ForMember(target => target.Name, options => options.MapFrom(source => source.Title))
            .ForMember(target => target.ParentType, options => options.MapFrom(source => source.CommunityTypeID))
            .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.ParentName, options => options.MapFrom(source => source.CommunityName))
            .ForMember(target => target.Tags, options => options.MapFrom(source => (source.Tags == null ? string.Empty : source.Tags)))
            .ForMember(
                target => target.Thumbnail,
                options => options.ResolveUsing(source =>
            {
                var thumbnailDetail     = new FileDetail();
                thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty;
                return(thumbnailDetail);
            }))
            .ForMember(
                target => target.ContentData,
                options => options.ResolveUsing(source =>
            {
                ContentTypes type = source.TypeID.ToEnum <int, ContentTypes>(ContentTypes.Generic);
                DataDetail dataDetail;

                if (type == ContentTypes.Link)
                {
                    dataDetail = new LinkDetail(source.ContentUrl, source.ContentID);
                }
                else
                {
                    var fileDetail       = new FileDetail();
                    fileDetail.ContentID = source.ContentID;
                    fileDetail.AzureID   = source.ContentAzureID;
                    dataDetail           = fileDetail;
                }

                dataDetail.Name        = source.Filename;
                dataDetail.ContentType = type;
                return(dataDetail);
            }));

            Mapper.CreateMap <CommunitiesView, CommunityDetails>()
            .ForMember(target => target.ID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.Name, options => options.MapFrom(source => source.CommunityName))
            .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType))
            .ForMember(target => target.AccessTypeID, options => options.MapFrom(source => (int)source.AccessType.ToEnum <string, AccessType>(AccessType.Private)))
            .ForMember(target => target.CommunityType, options => options.MapFrom(source => source.CommunityTypeID.ToEnum <int, CommunityTypes>(CommunityTypes.None)))
            .ForMember(target => target.SortOrder, options => options.Ignore())
            .ForMember(
                target => target.Thumbnail,
                options => options.ResolveUsing(source =>
            {
                var thumbnailDetail     = new FileDetail();
                thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty;
                return(thumbnailDetail);
            }));

            Mapper.CreateMap <AllCommunitiesView, CommunityDetails>()
            .ForMember(target => target.ID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.Name, options => options.MapFrom(source => source.CommunityName))
            .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType))
            .ForMember(target => target.AccessTypeID, options => options.MapFrom(source => (int)source.AccessType.ToEnum <string, AccessType>(AccessType.Private)))
            .ForMember(target => target.CommunityType, options => options.MapFrom(source => source.CommunityTypeID.ToEnum <int, CommunityTypes>(CommunityTypes.None)))
            .ForMember(target => target.SortOrder, options => options.Ignore())
            .ForMember(
                target => target.Thumbnail,
                options => options.ResolveUsing(source =>
            {
                var thumbnailDetail     = new FileDetail();
                thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty;
                return(thumbnailDetail);
            }));

            Mapper.CreateMap <FeaturedCommunitiesView, CommunityDetails>()
            .ForMember(target => target.ID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.Name, options => options.MapFrom(source => source.CommunityName))
            .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType))
            .ForMember(target => target.AccessTypeID, options => options.MapFrom(source => (int)source.AccessType.ToEnum <string, AccessType>(AccessType.Private)))
            .ForMember(target => target.CommunityType, options => options.MapFrom(source => source.CommunityTypeID.ToEnum <int, CommunityTypes>(CommunityTypes.None)))
            .ForMember(
                target => target.Thumbnail,
                options => options.ResolveUsing(source =>
            {
                var thumbnailDetail     = new FileDetail();
                thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty;
                return(thumbnailDetail);
            }));

            // Used by AdministrationService
            Mapper.CreateMap <OffensiveCommunities, OffensiveEntityDetails>()
            .ForMember(target => target.EntityID, options => options.MapFrom(source => source.CommunityID))
            .ForMember(target => target.EntityName, options => options.MapFrom(source => source.Community.Name))
            .ForMember(target => target.EntryID, options => options.MapFrom(source => source.OffensiveCommunitiesID))
            .ForMember(target => target.ReportedByID, options => options.MapFrom(source => source.ReportedByID))
            .ForMember(target => target.ReportedBy, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName))
            .ForMember(target => target.ReportedDatetime, options => options.MapFrom(source => source.ReportedDatetime))
            .ForMember(target => target.Reason, options => options.MapFrom(source => Resources.ResourceManager.GetString(source.OffensiveTypeID.ToEnum <int, ReportEntityType>(ReportEntityType.None).ToString())))
            .ForMember(target => target.Comment, options => options.MapFrom(source => source.Comments));

            Mapper.CreateMap <OffensiveContent, OffensiveEntityDetails>()
            .ForMember(target => target.EntityID, options => options.MapFrom(source => source.ContentID))
            .ForMember(target => target.EntityName, options => options.MapFrom(source => source.Content.Title))
            .ForMember(target => target.EntryID, options => options.MapFrom(source => source.OffensiveContentID))
            .ForMember(target => target.ReportedByID, options => options.MapFrom(source => source.ReportedByID))
            .ForMember(target => target.ReportedBy, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName))
            .ForMember(target => target.ReportedDatetime, options => options.MapFrom(source => source.ReportedDatetime))
            .ForMember(target => target.Reason, options => options.MapFrom(source => Resources.ResourceManager.GetString(source.OffensiveTypeID.ToEnum <int, ReportEntityType>(ReportEntityType.None).ToString())))
            .ForMember(target => target.Comment, options => options.MapFrom(source => source.Comments));

            Mapper.CreateMap <InviteRequestItem, InviteRequestContent>();
            Mapper.CreateMap <InviteRequestItem, InviteRequestItem>()
            .ForMember(target => target.EmailIdList, options => options.Ignore());
            Mapper.CreateMap <InviteRequestsView, InviteRequestItem>()
            .ForMember(target => target.EmailIdList, options => options.MapFrom(source => new Collection <string>()
            {
                source.EmailID
            }));

            Mapper.CreateMap <CommunityDetails, AdminEntityDetails>()
            .ForMember(target => target.EntityID, options => options.MapFrom(source => source.ID))
            .ForMember(target => target.EntityName, options => options.MapFrom(source => source.Name))
            .ForMember(target => target.Visibility, options => options.MapFrom(source => source.AccessTypeName))
            .ForMember(target => target.ModifiedDatetime, options => options.MapFrom(source => source.LastUpdatedDatetime))
            .ForMember(target => target.EntityType, options => options.UseValue(EntityType.Community))
            .ForMember(target => target.Category, options => options.MapFrom(source => source.CategoryID.ToEnum <int, CategoryType>(CategoryType.All)))
            .ForMember(target => target.CreatedBy, options => options.MapFrom(source => source.ProducedBy))
            .ForMember(target => target.CreatedByID, options => options.MapFrom(source => source.CreatedByID))
            .ForMember(target => target.DistributedBy, options => options.MapFrom(source => HttpContext.Current.Server.HtmlDecode(source.DistributedBy).GetTextFromHtmlString()));

            Mapper.CreateMap <ContentDetails, AdminEntityDetails>()
            .ForMember(target => target.EntityID, options => options.MapFrom(source => source.ID))
            .ForMember(target => target.EntityName, options => options.MapFrom(source => source.Name))
            .ForMember(target => target.Visibility, options => options.MapFrom(source => source.AccessTypeName))
            .ForMember(target => target.ModifiedDatetime, options => options.MapFrom(source => source.LastUpdatedDatetime))
            .ForMember(target => target.EntityType, options => options.UseValue(EntityType.Content))
            .ForMember(target => target.Category, options => options.MapFrom(source => source.CategoryID.ToEnum <int, CategoryType>(CategoryType.All)))
            .ForMember(target => target.CreatedBy, options => options.MapFrom(source => source.ProducedBy))
            .ForMember(target => target.CreatedByID, options => options.MapFrom(source => source.CreatedByID))
            .ForMember(target => target.DistributedBy, options => options.MapFrom(source => HttpContext.Current.Server.HtmlDecode(source.DistributedBy).GetTextFromHtmlString()));

            Mapper.CreateMap <ProfileDetails, AdminUserDetails>()
            .ForMember(target => target.UserID, options => options.MapFrom(source => source.ID))
            .ForMember(target => target.UserName, options => options.MapFrom(source => source.FirstName + " " + source.LastName))
            .ForMember(target => target.UserImageID, options => options.MapFrom(source => source.PictureID))
            .ForMember(target => target.Email, options => options.MapFrom(source => source.Email));

            Mapper.CreateMap <SearchView, EntityViewModel>()
            .ForMember(target => target.Tags, options => options.MapFrom(source => string.IsNullOrWhiteSpace(source.Tags) ? string.Empty : source.Tags))
            .ForMember(target => target.ParentType, options => options.Condition(source => !source.IsSourceValueNull));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Populates the ContentViewModel object's properties from the given ContentsView object's properties.
        /// </summary>
        /// <param name="thisObject">Current content view model on which the extension method is called</param>
        /// <param name="content">ContentInputViewModel model from which values to be read</param>
        public static void SetValuesFrom(this ContentDetails thisObject, ContentInputViewModel content)
        {
            if (thisObject != null && content != null)
            {
                // Populate the base values using the EntityViewModel's SetValuesFrom method.
                (thisObject as EntityDetails).SetValuesFrom(content);

                thisObject.DistributedBy = content.DistributedBy;
                thisObject.Citation      = content.Citation;

                // Set the access type for the content
                thisObject.AccessTypeID = content.AccessTypeID;

                thisObject.TourLength = content.TourLength;

                // Set content data properties.
                if (content.IsLink)
                {
                    thisObject.ContentData = new LinkDetail(content.ContentUrl);
                }
                else
                {
                    string[] fileDetails = content.ContentFileDetail.Split('~');

                    if (fileDetails.Count() == 5)
                    {
                        string mimeType = fileDetails[3];

                        // If the content file details does not have the following details
                        // then do not process the file.
                        DataDetail contentDetail = null;

                        if (mimeType.ToUpperInvariant().Equals(Constants.LinkMimeType.ToUpperInvariant()))
                        {
                            contentDetail = new LinkDetail(content.FileName);
                        }
                        else
                        {
                            var fileDetail = new FileDetail();

                            // Get file name and Content type.
                            fileDetail.Name        = content.FileName;
                            fileDetail.ContentType = fileDetails[0].GetContentTypes();

                            // Get File size.
                            long fileSize;
                            if (long.TryParse(fileDetails[1], out fileSize))
                            {
                                fileDetail.Size = fileSize;
                            }

                            fileDetail.AzureID = content.ContentDataID;

                            // Get content mime Type.
                            fileDetail.MimeType = fileDetails[3];

                            contentDetail = fileDetail;
                        }

                        // Set Content ID if present.
                        long contentID;
                        if (long.TryParse(fileDetails[4], out contentID))
                        {
                            contentDetail.ContentID = contentID;
                        }

                        thisObject.ContentData = contentDetail;
                    }
                }

                // Set video properties.
                if (content.VideoID != Guid.Empty && content.VideoFileDetail != null)
                {
                    var      video        = new FileDetail();
                    string[] videoDetails = content.VideoFileDetail.Split('~');

                    if (videoDetails.Count() == 5)
                    {
                        var fileDetail = new FileDetail();

                        // Get file name and Content type.
                        fileDetail.Name        = content.VideoName;
                        fileDetail.ContentType = videoDetails[0].GetContentTypes();

                        // Get File size.
                        long fileSize;
                        if (long.TryParse(videoDetails[1], out fileSize))
                        {
                            fileDetail.Size = fileSize;
                        }

                        fileDetail.AzureID = content.VideoID;

                        // Get content mime Type.
                        fileDetail.MimeType = videoDetails[3];

                        video = fileDetail;
                    }

                    thisObject.Video = video;
                }

                // Set associated file details.
                thisObject.AssociatedFiles = GetAssociatedFiles(content);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the associated files from content input view model.
        /// </summary>
        /// <param name="content">Input view model.</param>
        /// <returns>Associated files.</returns>
        private static IEnumerable <DataDetail> GetAssociatedFiles(ContentInputViewModel content)
        {
            var associatedFiles = new List <DataDetail>();

            if (content.PostedFileDetail != null)
            {
                for (int i = 0; i < content.PostedFileDetail.Count(); i++)
                {
                    var      file        = content.PostedFileDetail.ElementAt(i);
                    string[] fileDetails = file.Split('~');

                    if (fileDetails.Count() == 5)
                    {
                        string mimeType = fileDetails[3];

                        // If the posted file details does not have the following details
                        // then do not process the file.
                        DataDetail contentDetail = null;

                        if (mimeType.ToUpperInvariant().Equals(Constants.LinkMimeType.ToUpperInvariant()))
                        {
                            contentDetail = new LinkDetail(content.PostedFileName.ElementAt(i));
                        }
                        else
                        {
                            var fileDetail = new FileDetail();

                            // Get and set Content type.
                            fileDetail.ContentType = fileDetails[0].GetContentTypes();

                            // Get file name and extension.
                            fileDetail.Name = string.Format(
                                System.Globalization.CultureInfo.InvariantCulture,
                                "{0}{1}",
                                content.PostedFileName.ElementAt(i),
                                fileDetails[0]);

                            // Get File size.
                            long fileSize;
                            if (long.TryParse(fileDetails[1], out fileSize))
                            {
                                fileDetail.Size = fileSize;
                            }

                            // Get Azure ID
                            Guid fileID;
                            if (Guid.TryParse(fileDetails[2], out fileID))
                            {
                                fileDetail.AzureID = fileID;
                            }

                            // Get content mime Type.
                            fileDetail.MimeType = fileDetails[3];

                            contentDetail = fileDetail;
                        }

                        // Set Content ID if present.
                        long contentID;
                        if (long.TryParse(fileDetails[4], out contentID))
                        {
                            contentDetail.ContentID = contentID;
                        }

                        associatedFiles.Add(contentDetail);
                    }
                }
            }

            return(associatedFiles);
        }