SaveResult

Namespace: iRely.Common
We found 9 examples in language CSharp for this search. You will see 32 fragments of code.

        public static SaveResult getAsyncSaveResult(SaveResult saveResult)
        {
            return Implementation.getAsyncSaveResult(saveResult);
        }

        public static SaveResult getAsyncSaveResult(string asyncLocator)
        {
            return Implementation.getAsyncSaveResult(asyncLocator);
        }

        public static SaveResult insert(SObject recordToInsert, bool allOrNone)
        {
            return Implementation.insert(recordToInsert, allOrNone);
        }

        public static SaveResult insert(SObject recordToInsert, DMLOptions dmlOptions)
        {
            return Implementation.insert(recordToInsert, dmlOptions);
        }

        public static List<SaveResult> insertAsync(List<SObject> sobjects, AsyncSaveCallback callback)
        {
            return Implementation.insertAsync(sobjects, callback);
        }

        public static SaveResult insertAsync(SObject sobject, AsyncSaveCallback callback)
        {
            return Implementation.insertAsync(sobject, callback);
        }


        [TestMethod()]
        public void AddStandardReferenceTest_NullStandardReferenceReturnError()
        {
            string message = string.Empty;
            StandardReference stdReference = null;

            var saveResult = _target.AddStandardReference(stdReference, out message);
            Assert.IsNull(saveResult);
            Assert.AreEqual("Please fill in all required fields", message);
        }

using System;
using NKingime.Core.Option;
using NKingime.Utility.General;

namespace NKingime.Core.Service
{
    /// <summary>
    /// 保存消息结果。
    /// </summary>
    public class SaveResult : MessageResult<SaveResultOption>
    {
        /// <summary>
        /// 初始化一个<see cref="SaveResult"/>类型的成功实例。
        /// </summary>
        public SaveResult() : base(SaveResultOption.Success)
        {

        }

        /// <summary>
        /// 初始化一个<see cref="SaveResult"/>类型的新实例。
        /// </summary>
        /// <param name="result">结果。</param>
        public SaveResult(SaveResultOption result) : base(result)
        {

        }

        /// <summary>
        /// 初始化一个<see cref="SaveResult"/>类型的新实例。
        /// </summary>
        /// <param name="result">结果。</param>
        /// <param name="message">消息。</param>
        public SaveResult(SaveResultOption result, string message) : base(result, message)
        {

        }
    }
}


        [TestMethod]
        public void SimpleCreateTest()
        {
            foreach (var product in GetSimpleProductsCollection(SIMPLE_PRODUCTS_COUNT))
            {
                var saveResult = repository.Save(product);
                TestProductRecursive(product, saveResult);
                TestProductFromDB(product, saveResult.Id);
            }
        }

        [TestMethod]
        public void CreateComplexObjectTest()
        {
            var complexProduct = GetComplexProduct(COMPLEX_PRODUCT_CHILDS);
            var saveResult = repository.Save(complexProduct);
            TestProductRecursive(complexProduct, saveResult);
            TestProductFromDB(complexProduct, saveResult.Id);
        }

        [TestMethod]
        public void DeleteTest()
        {
            var product = GetComplexProduct(1);
            var saveResult = repository.Save(product);

            repository.Delete(saveResult.Id);
            var getResult = repository.Get(saveResult.Id);
            Assert.IsNull(getResult);
        }


        #endregion

        #region 增加

        public SaveResult Insert(TEntity entity, bool isSaveChange = true)
        {
            ////第一种方法
            //_dbSet.Attach(entity);
            //_context.Entry<TEntity>(entity).State = EntityState.Added;

            //第二种方法
            _dbSet.Add(entity); //EntityState.Detached

            return isSaveChange ? this.Save() : new SaveResult();
        }
        public SaveResult InsertMany(IEnumerable<TEntity> lst, bool isSaveChange = true)
        {
            _dbSet.AddRange(lst);

            return isSaveChange ? this.Save() : new SaveResult();
        }
        

        #endregion

        #region 编辑

        public SaveResult Update(TEntity entity, bool isSaveChange = true)
        {
            _dbSet.Attach(entity);
            _context.Entry(entity).State = EntityState.Modified;

            return isSaveChange ? this.Save() : new SaveResult();
        }

        public SaveResult Update(TPrimaryKey key, Action<TEntity> change, bool isSaveChange = true)
        {
            var entity = _dbSet.Find(key);
            if (entity == null) return new SaveResult { Status= SaveStatus.NonExist, Rows = 0, Message = "The entity is not exist!" };
            change(entity);
            return this.Update(entity, isSaveChange);
        }

        #endregion

        #region 删除

        public SaveResult Delete(TEntity entity, bool isSaveChange = true)
        {
            _dbSet.Attach(entity);
            _context.Entry(entity).State = EntityState.Deleted;
            return isSaveChange ? this.Save() : new SaveResult();
        }

        public SaveResult Delete(TPrimaryKey key,bool isSaveChange = true)
        {
            TEntity entity = this._dbSet.Find(key);
            if (entity == null) return new SaveResult { Status = SaveStatus.NonExist, Rows = 0, Message = "The entity is not exist!" };
            return this.Delete(entity, isSaveChange);
        }        


        #endregion Contructors

        #region Overrides

        public override void ExpandView(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            if (Id == 0)
            {
                ExtraFields = MixService.GetAppSetting<string>("DefaultPostAttr");
            }
            Cultures = LoadCultures(Specificulture, _context, _transaction);
            UrlAliases = GetAliases(_context, _transaction);
            if (!string.IsNullOrEmpty(this.Tags))
            {
                ListTag = JArray.Parse(this.Tags);
            }

            // Parsing Extra Properties fields
            Columns = new List<ModuleFieldViewModel>();
            JArray arrField = !string.IsNullOrEmpty(ExtraFields) ? JArray.Parse(ExtraFields) : new JArray();
            foreach (var field in arrField)
            {
                ModuleFieldViewModel thisField = new ModuleFieldViewModel()
                {
                    Name = MixCommonHelper.ParseJsonPropertyName(field["name"].ToString()),
                    Title = field["title"]?.ToString(),
                    Options = field["options"] != null ? field["options"].Value<JArray>() : new JArray(),
                    Priority = field["priority"] != null ? field["priority"].Value<int>() : 0,
                    DataType = (MixDataType)(int)field["dataType"],
                    Width = field["width"] != null ? field["width"].Value<int>() : 3,
                    IsUnique = field["isUnique"] != null ? field["isUnique"].Value<bool>() : true,
                    IsRequired = field["isRequired"] != null ? field["isRequired"].Value<bool>() : true,
                    IsDisplay = field["isDisplay"] != null ? field["isDisplay"].Value<bool>() : true,
                    IsSelect = field["isSelect"] != null ? field["isSelect"].Value<bool>() : false,
                    IsGroupBy = field["isGroupBy"] != null ? field["isGroupBy"].Value<bool>() : false,
                };
                Columns.Add(thisField);
            }

            // Parsing Extra Properties value
            Properties = new List<ExtraProperty>();

            if (!string.IsNullOrEmpty(ExtraProperties))
            {
                JArray arr = JArray.Parse(ExtraProperties);
                foreach (JToken item in arr)
                {
                    Properties.Add(item.ToObject<ExtraProperty>());
                }
            }
            //Get Templates
            this.Templates = this.Templates ?? MixTemplates.UpdateViewModel.Repository.GetModelListBy(
                t => t.Theme.Id == ActivedTheme && t.FolderType == this.TemplateFolderType).Data;
            View = MixTemplates.UpdateViewModel.GetTemplateByPath(Template, Specificulture, MixTemplateFolders.Posts, _context, _transaction);

            this.Template = $"{this.View?.FileFolder}/{this.View?.FileName}";

            var getPagePost = MixPagePosts.ReadViewModel.GetPagePostNavAsync(Id, Specificulture, _context, _transaction);
            if (getPagePost.IsSucceed)
            {
                this.Pages = getPagePost.Data;
                this.Pages.ForEach(c =>
                {
                    c.IsActived = MixPagePosts.ReadViewModel.Repository.CheckIsExists(n => n.PageId == c.PageId && n.PostId == Id, _context, _transaction);
                });
            }

            var getModulePost = MixModulePosts.ReadViewModel.GetModulePostNavAsync(Id, Specificulture, _context, _transaction);
            if (getModulePost.IsSucceed)
            {
                this.Modules = getModulePost.Data;
                this.Modules.ForEach(c =>
                {
                    c.IsActived = MixModulePosts.ReadViewModel.Repository.CheckIsExists(n => n.ModuleId == c.ModuleId && n.PostId == Id, _context, _transaction);
                });
            }
            var otherModules = MixModules.ReadListItemViewModel.Repository.GetModelListBy(
                m => (m.Type == (int)MixModuleType.Content || m.Type == (int)MixModuleType.ListPost)
                && m.Specificulture == Specificulture
                && !Modules.Any(n => n.ModuleId == m.Id && n.Specificulture == m.Specificulture)
                , "CreatedDateTime", Heart.Enums.DisplayDirection.Desc, null, 0, _context, _transaction);
            foreach (var item in otherModules.Data.Items)
            {
                Modules.Add(new MixModulePosts.ReadViewModel()
                {
                    ModuleId = item.Id,
                    Image = item.Image,
                    PostId = Id,
                    Description = Title
                });
            }

            // Medias
            var getPostMedia = MixPostMedias.ReadViewModel.Repository.GetModelListBy(n => n.PostId == Id && n.Specificulture == Specificulture, _context, _transaction);
            if (getPostMedia.IsSucceed)
            {
                MediaNavs = getPostMedia.Data.OrderBy(p => p.Priority).ToList();
                MediaNavs.ForEach(n => n.IsActived = true);
            }
            // Modules
            var getPostModule = MixPostModules.ReadViewModel.Repository.GetModelListBy(
                n => n.PostId == Id && n.Specificulture == Specificulture, _context, _transaction);
            if (getPostModule.IsSucceed)
            {
                ModuleNavs = getPostModule.Data.OrderBy(p => p.Priority).ToList();
                foreach (var item in ModuleNavs)
                {
                    item.IsActived = true;
                    item.Module.LoadData(postId: Id, _context: _context, _transaction: _transaction);
                }
            }

            // Related Posts
            PostNavs = GetRelated(_context, _transaction);
            var otherPosts = MixPosts.ReadListItemViewModel.Repository.GetModelListBy(
                m => m.Id != Id && m.Specificulture == Specificulture
                    && !PostNavs.Any(n => n.SourceId == Id)
                    , "CreatedDateTime", Heart.Enums.DisplayDirection.Desc, 10, 0, _context, _transaction);
            foreach (var item in otherPosts.Data.Items)
            {
                PostNavs.Add(new MixPostPosts.ReadViewModel()
                {
                    SourceId = Id,
                    Image = item.ImageUrl,
                    DestinationId = item.Id,
                    Description = item.Title
                });
            }
        }

        public override MixPost ParseModel(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            if (Id == 0)
            {
                Id = Repository.Max(c => c.Id, _context, _transaction).Data + 1;
                CreatedDateTime = DateTime.UtcNow;
            }
            LastModified = DateTime.UtcNow;
            PublishedDateTime = PublishedDateTime?.ToUniversalTime();

            //  Parsing Extra Fields to json string
            var arrField = Columns != null ? JArray.Parse(
                Newtonsoft.Json.JsonConvert.SerializeObject(Columns.OrderBy(c => c.Priority).Where(
                    c => !string.IsNullOrEmpty(c.Name)))) : new JArray();
            ExtraFields = arrField.ToString(Newtonsoft.Json.Formatting.None);

            // Parsing Extra Properties value
            if (Properties != null && Properties.Count > 0)
            {
                JArray arrProperties = new JArray();
                foreach (var p in Properties.Where(p => !string.IsNullOrEmpty(p.Value) && !string.IsNullOrEmpty(p.Name)))
                {
                    arrProperties.Add(JObject.FromObject(p));
                }
                ExtraProperties = arrProperties.ToString(Formatting.None)?.Trim();
            }

            Template = View != null ? string.Format(@"{0}/{1}{2}", View.FolderType, View.FileName, View.Extension) : Template;
            if (ThumbnailFileStream != null)
            {
                string folder = MixCmsHelper.GetUploadFolder(Specificulture);
                string filename = MixCommonHelper.GetRandomName(ThumbnailFileStream.Name);
                bool saveThumbnail = MixCommonHelper.SaveFileBase64(folder, filename, ThumbnailFileStream.Base64);
                if (saveThumbnail)
                {
                    MixCommonHelper.RemoveFile(Thumbnail);
                    Thumbnail = $"{folder}/{filename}";
                }
            }
            if (ImageFileStream != null)
            {
                string folder = MixCmsHelper.GetUploadFolder(Specificulture);
                string filename = MixCommonHelper.GetRandomName(ImageFileStream.Name);
                bool saveImage = MixCommonHelper.SaveFileBase64(folder, filename, ImageFileStream.Base64);
                if (saveImage)
                {
                    MixCommonHelper.RemoveFile(Image);
                    Image = $"{folder}/{filename}";
                }
            }

            if (!string.IsNullOrEmpty(Image) && Image[0] == '/') { Image = Image.Substring(1); }
            if (!string.IsNullOrEmpty(Thumbnail) && Thumbnail[0] == '/') { Thumbnail = Thumbnail.Substring(1); }
            Tags = ListTag.ToString(Newtonsoft.Json.Formatting.None);
            GenerateSEO();

            return base.ParseModel(_context, _transaction);
        }

        #region Async Methods

        public override async Task<RepositoryResponse<bool>> SaveSubModelsAsync(
            MixPost parent
            , MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var result = new RepositoryResponse<bool>() { IsSucceed = true };
            try
            {
                if (result.IsSucceed)
                {
                    foreach (var item in UrlAliases)
                    {
                        item.SourceId = parent.Id.ToString();
                        item.Type = MixUrlAliasType.Post;
                        item.Specificulture = Specificulture;
                        var saveResult = await item.SaveModelAsync(false, _context, _transaction);
                        result.IsSucceed = saveResult.IsSucceed;
                        if (!result.IsSucceed)
                        {
                            result.Exception = saveResult.Exception;
                            result.Errors.AddRange(saveResult.Errors);
                            break;
                        }
                    }
                }
                if (result.IsSucceed)
                {
                    var startMediaId = MixMedias.UpdateViewModel.Repository.Max(c => c.Id, _context, _transaction).Data;
                    foreach (var navMedia in MediaNavs)
                    {
                        if (navMedia.Media != null)
                        {
                            startMediaId += 1;
                            navMedia.Media.Specificulture = Specificulture;
                            navMedia.Media.Id = startMediaId;
                            var saveMedia = await navMedia.Media.SaveModelAsync(false, _context, _transaction);
                            if (saveMedia.IsSucceed)
                            {
                                navMedia.PostId = parent.Id;
                                navMedia.MediaId = saveMedia.Data.Model.Id;
                                navMedia.Specificulture = parent.Specificulture;
                                var saveResult = await navMedia.SaveModelAsync(false, _context, _transaction);
                                result.IsSucceed = saveResult.IsSucceed;
                                if (!result.IsSucceed)
                                {
                                    result.Exception = saveResult.Exception;
                                    Errors.AddRange(saveResult.Errors);
                                }
                            }
                            else
                            {
                                result.IsSucceed = false;
                                result.Exception = saveMedia.Exception;
                                Errors.AddRange(saveMedia.Errors);
                            }
                        }
                    }
                }
                if (result.IsSucceed)
                {
                    foreach (var navModule in ModuleNavs)
                    {
                        navModule.PostId = parent.Id;
                        navModule.Specificulture = parent.Specificulture;
                        navModule.Status = MixContentStatus.Published;
                        if (navModule.IsActived)
                        {
                            var saveResult = await navModule.SaveModelAsync(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                        else
                        {
                            var saveResult = await navModule.RemoveModelAsync(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                    }
                }

                if (result.IsSucceed)
                {
                    foreach (var navPost in PostNavs)
                    {
                        navPost.SourceId = parent.Id;
                        navPost.Status = MixContentStatus.Published;
                        navPost.Specificulture = parent.Specificulture;
                        if (navPost.IsActived)
                        {
                            var saveResult = await navPost.SaveModelAsync(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                        else
                        {
                            var saveResult = await navPost.RemoveModelAsync(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                    }
                }
                if (result.IsSucceed)
                {
                    // Save Parent Category
                    foreach (var item in Pages)
                    {
                        item.PostId = parent.Id;
                        item.Description = parent.Title;
                        item.Image = ThumbnailUrl;
                        item.Status = MixContentStatus.Published;
                        if (item.IsActived)
                        {
                            var saveResult = await item.SaveModelAsync(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                        else
                        {
                            var saveResult = await item.RemoveModelAsync(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                    }
                }

                if (result.IsSucceed)
                {
                    // Save Parent Modules
                    foreach (var item in Modules)
                    {
                        item.PostId = parent.Id;
                        item.Description = parent.Title;
                        item.Image = ThumbnailUrl;
                        item.Status = MixContentStatus.Published;
                        if (item.IsActived)
                        {
                            var saveResult = await item.SaveModelAsync(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                        else
                        {
                            var saveResult = await item.RemoveModelAsync(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                    }
                }

                return result;
            }
            catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only
            {
                result.IsSucceed = false;
                result.Exception = ex;
                return result;
            }
        }

        #endregion Async Methods

        #region Sync Methods

        public override RepositoryResponse<bool> SaveSubModels(
            MixPost parent
            , MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var result = new RepositoryResponse<bool>() { IsSucceed = true };
            try
            {
                if (result.IsSucceed)
                {
                    var startMediaId = MixMedias.UpdateViewModel.Repository.Max(c => c.Id, _context, _transaction).Data;
                    foreach (var navMedia in MediaNavs)
                    {
                        if (navMedia.Media != null)
                        {
                            startMediaId += 1;
                            navMedia.Media.Specificulture = Specificulture;
                            navMedia.Media.Id = startMediaId;
                            var saveMedia = navMedia.Media.SaveModel(false, _context, _transaction);
                            if (saveMedia.IsSucceed)
                            {
                                navMedia.PostId = parent.Id;
                                navMedia.MediaId = saveMedia.Data.Model.Id;
                                navMedia.Specificulture = parent.Specificulture;
                                var saveResult = navMedia.SaveModel(false, _context, _transaction);
                                result.IsSucceed = saveResult.IsSucceed;
                                if (!result.IsSucceed)
                                {
                                    result.Exception = saveResult.Exception;
                                    Errors.AddRange(saveResult.Errors);
                                }
                            }
                            else
                            {
                                result.IsSucceed = false;
                                result.Exception = saveMedia.Exception;
                                Errors.AddRange(saveMedia.Errors);
                            }
                        }
                    }
                }
                if (result.IsSucceed)
                {
                    foreach (var navModule in ModuleNavs)
                    {
                        navModule.PostId = parent.Id;
                        navModule.Specificulture = parent.Specificulture;
                        navModule.Status = MixContentStatus.Published;
                        if (navModule.IsActived)
                        {
                            var saveResult = navModule.SaveModel(true, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                        else
                        {
                            var saveResult = navModule.RemoveModel(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                    }
                }

                if (result.IsSucceed)
                {
                    // Save Parent Category
                    foreach (var item in Pages)
                    {
                        item.PostId = parent.Id;
                        item.Description = parent.Title;
                        item.Image = ThumbnailUrl;
                        item.Status = MixContentStatus.Published;
                        if (item.IsActived)
                        {
                            var saveResult = item.SaveModel(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                        else
                        {
                            var saveResult = item.RemoveModel(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                    }
                }

                if (result.IsSucceed)
                {
                    // Save Parent Modules
                    foreach (var item in Modules)
                    {
                        item.PostId = parent.Id;
                        item.Description = parent.Title;
                        item.Image = ThumbnailUrl;
                        item.Status = MixContentStatus.Published;
                        if (item.IsActived)
                        {
                            var saveResult = item.SaveModel(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                        else
                        {
                            var saveResult = item.RemoveModel(false, _context, _transaction);
                            result.IsSucceed = saveResult.IsSucceed;
                            if (!result.IsSucceed)
                            {
                                result.Exception = saveResult.Exception;
                                Errors.AddRange(saveResult.Errors);
                            }
                        }
                    }
                }

                return result;
            }
            catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only
            {
                result.IsSucceed = false;
                result.Exception = ex;
                return result;
            }
        }

        public override RepositoryResponse<bool> RemoveRelatedModels(SyncViewModel view, MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            RepositoryResponse<bool> result = new RepositoryResponse<bool>()
            {
                IsSucceed = true
            };

            if (result.IsSucceed)
            {
                var navCate = _context.MixPagePost.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToList();
                foreach (var item in navCate)
                {
                    _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
                }
            }

            if (result.IsSucceed)
            {
                var navModule = _context.MixModulePost.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToList();
                foreach (var item in navModule)
                {
                    _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
                }
            }

            if (result.IsSucceed)
            {
                var navMedia = _context.MixPostMedia.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToList();
                foreach (var item in navMedia)
                {
                    _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
                }
            }
            if (result.IsSucceed)
            {
                var navModule = _context.MixPostModule.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToList();
                foreach (var item in navModule)
                {
                    _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
                }
            }

            if (result.IsSucceed)
            {
                var navRelated = _context.MixPostMedia.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToList();
                foreach (var item in navRelated)
                {
                    _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
                }
            }

            if (result.IsSucceed)
            {
                var navs = _context.MixUrlAlias.Where(n => n.SourceId == Id.ToString() && n.Type == (int)MixUrlAliasType.Post && n.Specificulture == Specificulture).ToList();
                foreach (var item in navs)
                {
                    _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
                }
            }

            result.IsSucceed = (_context.SaveChanges() > 0);
            return result;
        }

        #endregion Sync Methods

        #endregion Overrides

        #region Expands

        private List<SupportedCulture> LoadCultures(string initCulture = null, MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var getCultures = SystemCultureViewModel.Repository.GetModelList(_context, _transaction);
            var result = new List<SupportedCulture>();
            if (getCultures.IsSucceed)
            {
                foreach (var culture in getCultures.Data)
                {
                    result.Add(
                        new SupportedCulture()
                        {
                            Icon = culture.Icon,
                            Specificulture = culture.Specificulture,
                            Alias = culture.Alias,
                            FullName = culture.FullName,
                            Description = culture.FullName,
                            Id = culture.Id,
                            Lcid = culture.Lcid,
                            IsSupported = culture.Specificulture == initCulture || _context.MixPost.Any(p => p.Id == Id && p.Specificulture == culture.Specificulture)
                        });
                }
            }
            return result;
        }

        public async Task<SaveResult> Complete(CancellationToken cancellationToken)
        {
            var saveResult = new SaveResult();
            var newOrModifiedEntries = _context.ChangeTracker.Entries().Where(x => x.State == EntityState.Added ||
                                                                           x.State == EntityState.Modified
                                                                        || x.State == EntityState.Deleted);
         
            try
            {
                if (newOrModifiedEntries.Count() > 0)
                {
                    var rowsAffected = await _context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

                    saveResult.rowsAffected = rowsAffected;
                    saveResult.success = true;
                    saveResult.message = "Successfully saved.";
                }
            }
            catch (DbUpdateConcurrencyException ex)
            {
                foreach (var entry in ex.Entries)
                {
                    var proposedValues = entry.CurrentValues;
                    var dbValues = entry.GetDatabaseValues();
                }
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;

                if (ex.InnerException.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint"))
                {
                    errorMessage = "Unable to delete. Record is being used.";
                }

                saveResult.success = false;
                saveResult.message = errorMessage;
            }

            return saveResult;


        }

        public void Dispose()
        {
            _context.Dispose();
        }

        static void Main(string[] args)
        {
            var allFilesTobeCheck = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll",
                SearchOption.AllDirectories);

            foreach (var s in allFilesTobeCheck)
            {
                ReferenceManager.CheckFile(s);
            }

            var result = ReferenceManager.GetConflicts();
            var saveResult = new StringBuilder();
            foreach (var s in result)
            {
                Console.WriteLine(s);
                saveResult.AppendLine(s);
            }

            if (saveResult.Length > 0)
            {
                File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                        $"检测结果{DateTime.Now.ToString("yyyyMMddHHmmss")}.txt"), saveResult.ToString());
            }

            Console.WriteLine("探测完毕");
            Console.ReadKey();
        }

        void InsertInsave(UserSavesHistory save, ISPDataContext context);
        SaveResult UpdateSave(int confirmUserId, int saveId, double amount, string movementNote, string note, ISPDataContext context);
        List<UserSave> SavesOfUser(int userId, ISPDataContext context);
        SaveResult BranchAndUserSaves(int saveId, int userId, double amount, string note1, string note2, ISPDataContext db6);
        bool CanSave(int saveId, decimal amount, ISPDataContext context);
        bool CanSaveBranch(int saveId, decimal amount, ISPDataContext context);

iRely.Common.SaveResult : Object

Constructors :

public SaveResult()

Methods :

public Int32 get_RowsAffected()
public Void set_RowsAffected(Int32 value = )
public Boolean get_HasError()
public Void set_HasError(Boolean value = )
public ServerException get_Exception()
public Void set_Exception(ServerException value = )
public Exception get_BaseException()
public Void set_BaseException(Exception value = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()