Пример #1
0
        public Return PublishLive()
        {
            var returnObj    = new Return();
            var liveVersion  = BaseMapper.GetObjectFromContext((MediaDetail)this.Media.GetLiveMediaDetail());
            var selectedItem = BaseMapper.GetObjectFromContext((MediaDetail)this);

            selectedItem.HistoryVersionNumber  = 0;
            selectedItem.HistoryForMediaDetail = null;
            selectedItem.IsDraft     = false;
            selectedItem.PublishDate = DateTime.Now;
            //selectedItem.ShowInMenu = true;

            IEnumerable <MediaDetail> items = new List <MediaDetail>();

            if (liveVersion != null)
            {
                items = liveVersion.History.ToList();

                foreach (var item in items)
                {
                    if (item.ID != selectedItem.ID)
                    {
                        var tmpItem = BaseMapper.GetObjectFromContext(item);
                        item.HistoryForMediaDetailID = selectedItem.ID;
                    }
                }
            }

            foreach (var fieldAssociation in selectedItem.FieldAssociations)
            {
                var index = 1;
                foreach (var history in fieldAssociation.MediaDetail.History)
                {
                    history.HistoryForMediaDetail = fieldAssociation.MediaDetail;
                    history.HistoryVersionNumber  = 1;

                    index++;
                }

                fieldAssociation.MediaDetail.HistoryForMediaDetail = null;
                fieldAssociation.MediaDetail.HistoryVersionNumber  = 0;
            }

            foreach (var field in selectedItem.Fields)
            {
                foreach (var fieldAssociation in field.FieldAssociations)
                {
                    var index = 1;

                    foreach (var mediaDetail in fieldAssociation.MediaDetail.Media.MediaDetails)
                    {
                        mediaDetail.HistoryForMediaDetail = fieldAssociation.MediaDetail;
                        mediaDetail.HistoryVersionNumber  = 1;

                        index++;
                    }

                    fieldAssociation.MediaDetail.HistoryForMediaDetail = null;
                    fieldAssociation.MediaDetail.HistoryVersionNumber  = 0;
                }

                if (liveVersion != null)
                {
                    field.FrontEndSubmissions = liveVersion.LoadField(field.FieldCode)?.FrontEndSubmissions;
                }
            }

            foreach (var mediaTypeField in selectedItem.MediaType.Fields)
            {
                if (!selectedItem.Fields.Any(i => i.FieldCode == mediaTypeField.FieldCode))
                {
                    var mediaDetailField = new MediaDetailField();
                    mediaDetailField.CopyFrom(mediaTypeField);

                    mediaDetailField.UseMediaTypeFieldFrontEndLayout = true;
                    mediaDetailField.UseMediaTypeFieldDescription    = true;

                    mediaDetailField.MediaTypeField = mediaTypeField;

                    mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now;

                    mediaDetailField.OrderIndex = selectedItem.Fields.Count;
                    selectedItem.Fields.Add(mediaDetailField);
                }
            }


            if (liveVersion != null)
            {
                if (items.Any())
                {
                    liveVersion.HistoryVersionNumber = items.OrderByDescending(i => i.HistoryVersionNumber).FirstOrDefault().HistoryVersionNumber + 1;
                }
                else
                {
                    liveVersion.HistoryVersionNumber = 1;
                }

                liveVersion.HistoryForMediaDetail = (MediaDetail)selectedItem;


                var associations = BaseMapper.GetDataModel().FieldAssociations.Where(i => i.AssociatedMediaDetailID == liveVersion.ID);

                foreach (var association in associations)
                {
                    association.MediaDetail = (MediaDetail)selectedItem;
                }
            }

            returnObj = MediaDetailsMapper.Update(selectedItem);

            if (!returnObj.IsError)
            {
                if (liveVersion != null)
                {
                    liveVersion.HistoryForMediaDetailID = selectedItem.ID;
                    returnObj = MediaDetailsMapper.Update(liveVersion);
                }

                if (!returnObj.IsError)
                {
                    ContextHelper.Clear(ContextType.Cache);
                    FileCacheHelper.ClearAllCache();

                    return(returnObj);
                }
                else
                {
                    return(returnObj);
                }
            }
            else
            {
                return(returnObj);
            }
        }
 public static DirectoryInfo GetUploadFolder(MediaDetailField field, string baseUploadFolder = "~/media/uploads/")
 {
     return(new DirectoryInfo(FrameworkLibrary.URIHelper.ConvertToAbsPath(baseUploadFolder + "medias/" + field.MediaDetail.MediaID + "/media-details/" + field.MediaDetail.ID + "/fields/" + field.ID + "/")));
 }