Exemplo n.º 1
0
        private Return SaveHistory(IMediaDetail history)
        {
            selectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);
            history.HistoryForMediaDetailID = selectedItem.ID;

            if (selectedItem.History.Count == 0)
            {
                history.HistoryVersionNumber = 1;
            }
            else
            {
                history.HistoryVersionNumber = selectedItem.History.OrderByDescending(i => i.HistoryVersionNumber).Take(1).FirstOrDefault().HistoryVersionNumber + 1;
            }

            if (selectedItem.History.Count >= MediaDetailsMapper.MaxHistory)
            {
                int count = selectedItem.History.Count - MediaDetailsMapper.MaxHistory;
                IEnumerable <MediaDetail> items = selectedItem.History.OrderBy(i => i.HistoryVersionNumber).Take(count);

                foreach (MediaDetail item in items)
                {
                    if (!item.IsDraft)
                    {
                        MediaDetailsMapper.ClearObjectRelations(item);
                        MediaDetailsMapper.DeleteObjectFromContext(item);
                    }
                }
            }

            /*if (history.MainContent.Trim() == "")
             *  history.MainContent = "TBD";*/

            return(MediaDetailsMapper.Insert(history));
        }