Exemple #1
0
        public virtual bool Create(V item, bool useModelCulture = false)
        {
            if (item == null)
            {
                return(false);
            }

            var result     = true;
            var dataObject = new JoinedItem <T, TT>();

            CopyModelToItem(dataObject, item);
            result &= _rep.Create(dataObject.Item);
            CopyModelToTrans(dataObject, item);
            if (useModelCulture && item is ILocalizableModel)
            {
                dataObject.ItemTranslation.Culture = (item as ILocalizableModel).ContentCulture;
            }
            else
            {
                dataObject.ItemTranslation.Culture = MainCulture;
            }
            result &= _repTrans.Create(dataObject.ItemTranslation);
            result &= _rep.SubmitChanges();

            if (result)
            {
                CopyDataToModel(dataObject, item);
                MergeSubItems(item);
                GetSubItems(item);
            }
            return(result);
        }
        protected virtual bool Update(V m, PrimaryKey key)
        {
            var result = false;

            if (m != null)
            {
                try
                {
                    var existing = repository.FindByPrimaryKey(key);
                    if (existing == null)
                    {
                        return(false);
                    }
                    CopyModelToData(existing, m);
                    result = repository.SubmitChanges();
                    if (result)
                    {
                        MergeSubItems(m);
                    }
                }
                catch (Exception ex)
                {
                    result = false;
                    logger.LogException(ex);
                }
            }

            return(result);
        }
Exemple #3
0
        protected virtual bool Update(V m, PrimaryKey key, bool mergeSubItems = true, bool useModelCulture = false)
        {
            if (m == null)
            {
                return(false);
            }

            var result = true;

            try
            {
                var existing = FindByPrimaryKeyInternal(key, true);
                if (existing == null)
                {
                    return(false);
                }

                var createTrans = false;
                if (existing.ItemTranslation == null)
                {
                    createTrans = true;
                    existing.ItemTranslation = new TT();
                }
                CopyModelToItem(existing, m);
                result &= _rep.SubmitChanges();
                CopyModelToTrans(existing, m);
                if (useModelCulture && m is ILocalizableModel)
                {
                    existing.ItemTranslation.Culture = (m as ILocalizableModel).ContentCulture;
                }
                else
                {
                    existing.ItemTranslation.Culture = MainCulture;
                }
                if (createTrans)
                {
                    _repTrans.Create(existing.ItemTranslation);
                }
                result &= _repTrans.SubmitChanges();
                if (result && mergeSubItems)
                {
                    CopyDataToModel(existing, m);
                    MergeSubItems(m);
                }
            }
            catch (Exception ex)
            {
                result = false;
                _logger.LogException(ex);
            }
            return(result);
        }