public override async Task <RepositoryResponse <ImportViewModel> > SaveModelAsync(bool isSaveSubModels = false, MixCmsContext _context = null, IDbContextTransaction _transaction = null) { UnitOfWorkHelper <MixCmsContext> .InitTransaction(_context, _transaction, out MixCmsContext context, out IDbContextTransaction transaction, out bool isRoot); try { var result = await base.SaveModelAsync(isSaveSubModels, context, transaction); if (result.IsSucceed && !string.IsNullOrEmpty(ParentId)) { var getNav = MixRelatedAttributeDatas.UpdateViewModel.Repository.CheckIsExists( m => m.DataId == Id && m.ParentId == ParentId && m.ParentType == ParentType && m.Specificulture == Specificulture , context, transaction); if (!getNav) { var nav = new MixRelatedAttributeDatas.UpdateViewModel() { DataId = Id, Specificulture = Specificulture, AttributeSetId = AttributeSetId, AttributeSetName = AttributeSetName, ParentType = ParentType, ParentId = ParentId, Status = MixContentStatus.Published }; var saveResult = await nav.SaveModelAsync(false, context, transaction); if (!saveResult.IsSucceed) { result.IsSucceed = false; result.Exception = saveResult.Exception; result.Errors = saveResult.Errors; } } } UnitOfWorkHelper <MixCmsContext> .HandleTransaction(result.IsSucceed, isRoot, transaction); if (result.IsSucceed) { Obj = Helper.ParseData(Id, Specificulture, context, transaction); } return(result); } catch (Exception ex) { return(UnitOfWorkHelper <MixCmsContext> .HandleException <ImportViewModel>(ex, isRoot, transaction)); } finally { if (isRoot) { transaction.Dispose(); context.Dispose(); } } }
public override async Task <RepositoryResponse <UpdateViewModel> > SaveModelAsync(bool isSaveSubModels = false, MixCmsContext _context = null, IDbContextTransaction _transaction = null) { UnitOfWorkHelper <MixCmsContext> .InitTransaction(_context, _transaction, out MixCmsContext context, out IDbContextTransaction transaction, out bool isRoot); try { var result = await base.SaveModelAsync(isSaveSubModels, context, transaction); // if save current data success and there is related parent data if (result.IsSucceed && !string.IsNullOrEmpty(ParentId)) { MixRelatedAttributeDatas.UpdateViewModel nav = new MixRelatedAttributeDatas.UpdateViewModel() { DataId = result.Data.Id, Specificulture = Specificulture, AttributeSetId = result.Data.AttributeSetId, AttributeSetName = result.Data.AttributeSetName, ParentId = ParentId, ParentType = ParentType }; var saveNav = await nav.SaveModelAsync(true, context, transaction); result.IsSucceed = result.IsSucceed && saveNav.IsSucceed; result.Errors = saveNav.Errors; result.Exception = saveNav.Exception; } UnitOfWorkHelper <MixCmsContext> .HandleTransaction(result.IsSucceed, isRoot, transaction); return(result); } catch (Exception ex) { return(UnitOfWorkHelper <MixCmsContext> .HandleException <UpdateViewModel>(ex, isRoot, transaction)); } finally { if (isRoot) { UnitOfWorkHelper <MixCmsContext> .CloseDbContext(ref context, ref transaction); } } }