public RepositoryResponse <InfoModuleDataViewModel> Create() { SiocModuleData article = new SiocModuleData() { Specificulture = _lang }; return(new RepositoryResponse <InfoModuleDataViewModel>() { IsSucceed = true, Data = new InfoModuleDataViewModel(article) }); }
public async Task <RepositoryResponse <ApiModuleDataViewModel> > DetailsAsync(string viewType, int moduleId, string id = null) { if (string.IsNullOrEmpty(id)) { var getModule = await InfoModuleViewModel.Repository.GetSingleModelAsync( m => m.Id == moduleId && m.Specificulture == _lang).ConfigureAwait(false); if (getModule.IsSucceed) { var model = new SiocModuleData( ) { ModuleId = moduleId, Specificulture = _lang, Fields = getModule.Data.Fields }; return(new RepositoryResponse <ApiModuleDataViewModel>() { IsSucceed = true, Data = await ApiModuleDataViewModel.InitViewAsync(model) }); } else { return(new RepositoryResponse <ApiModuleDataViewModel>() { IsSucceed = false }); } } else { var be = await ApiModuleDataViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang); return(be); } }
public override RepositoryResponse <bool> SaveSubModels(SiocProduct parent, SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { bool result = true; try { // Save Template var saveTemplate = View.SaveModel(false, _context, _transaction); if (saveTemplate.IsSucceed) { Errors.AddRange(saveTemplate.Errors); } result = result && saveTemplate.IsSucceed; if (result) { // Save Parent Category foreach (var item in Categories) { item.ProductId = Id; if (item.IsActived) { var saveResult = item.SaveModel(false, _context, _transaction); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } else { var saveResult = item.RemoveModel(false, _context, _transaction); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } } } if (result) { // Save Parent Modules foreach (var item in Modules) { item.ProductId = Id; if (item.IsActived) { var saveResult = item.SaveModel(false, _context, _transaction); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } else { var saveResult = item.RemoveModel(false, _context, _transaction); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } } } if (result) { // Save Children Category foreach (var item in ModuleNavs) { item.ProductId = Id; if (item.IsActived) { var saveResult = item.SaveModel(false, _context, _transaction); } else { var saveResult = item.RemoveModel(true, _context, _transaction); result = saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); Exception = saveResult.Exception; } } } } //save submodules data if (result) { foreach (var module in ActivedModules) { module.Data.Items = new List <InfoModuleDataViewModel>(); foreach (var data in module.Data.JsonItems) { SiocModuleData model = new SiocModuleData() { Id = data.Value <string>("id") ?? Guid.NewGuid().ToString(), Specificulture = module.Specificulture, ProductId = Id, ModuleId = module.Id, Fields = module.Fields, CreatedDateTime = DateTime.UtcNow, UpdatedDateTime = DateTime.UtcNow }; List <ModuleFieldViewModel> cols = module.Columns; JObject val = new JObject(); foreach (JProperty prop in data.Properties()) { var col = cols.FirstOrDefault(c => c.Name == prop.Name); if (col != null) { JObject fieldVal = new JObject { new JProperty("dataType", col.DataType), new JProperty("value", prop.Value) }; val.Add(new JProperty(prop.Name, fieldVal)); } } model.Value = val.ToString(Newtonsoft.Json.Formatting.None); var vmData = new InfoModuleDataViewModel(model); var saveResult = vmData.SaveModel(false, _context, _transaction); if (saveResult.IsSucceed) { module.Data.Items.Add(vmData); } else { Errors.AddRange(saveResult.Errors); Exception = saveResult.Exception; } result = result && saveResult.IsSucceed; } } } if (result) { foreach (var navMedia in MediaNavs) { if (navMedia.IsActived) { navMedia.ProductId = parent.Id; var saveResult = navMedia.SaveModel(false, _context, _transaction); } else { navMedia.ProductId = parent.Id; var saveResult = navMedia.RemoveModel(false, _context, _transaction); result = saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); Exception = saveResult.Exception; } } } } return(new RepositoryResponse <bool>() { IsSucceed = result, Data = result, Errors = Errors, Exception = Exception }); } catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only { result = false; return(new RepositoryResponse <bool>() { IsSucceed = false, Data = false, Exception = ex }); } }
public override async Task <RepositoryResponse <bool> > SaveSubModelsAsync( SiocProduct parent , SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { var result = new RepositoryResponse <bool>() { IsSucceed = true }; try { // Save Template var saveTemplate = await View.SaveModelAsync(true, _context, _transaction); result.IsSucceed = result.IsSucceed && saveTemplate.IsSucceed; if (!saveTemplate.IsSucceed) { result.Errors.AddRange(saveTemplate.Errors); result.Exception = saveTemplate.Exception; } // Save url alias if (result.IsSucceed) { UrlAlias.IsClone = IsClone; UrlAlias.Cultures = Cultures; UrlAlias.SourceId = parent.Id.ToString(); UrlAlias.Type = SWCmsConstants.UrlAliasType.Product; var saveUrl = await UrlAlias.SaveModelAsync(false, _context, _transaction); result.Errors.AddRange(saveUrl.Errors); result.Exception = saveUrl.Exception; result.IsSucceed = saveUrl.IsSucceed; } if (result.IsSucceed) { // Save Parent Category foreach (var item in Categories) { item.ProductId = parent.Id; 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.ProductId = parent.Id; 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 Children Category foreach (var item in ModuleNavs) { item.ProductId = parent.Id; 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(true, _context, _transaction); result.IsSucceed = saveResult.IsSucceed; if (!result.IsSucceed) { result.Exception = saveResult.Exception; Errors.AddRange(saveResult.Errors); } } } } //save submodules data if (result.IsSucceed) { foreach (var module in ActivedModules) { module.Data.Items = new List <InfoModuleDataViewModel>(); foreach (var data in module.Data.JsonItems) { SiocModuleData model = new SiocModuleData() { Id = data.Value <string>("id") ?? Guid.NewGuid().ToString(), Specificulture = module.Specificulture, ProductId = parent.Id, ModuleId = module.Id, Fields = module.Fields, CreatedDateTime = DateTime.UtcNow, UpdatedDateTime = DateTime.UtcNow }; List <ModuleFieldViewModel> cols = module.Columns; JObject val = new JObject(); foreach (JProperty prop in data.Properties()) { var col = cols.FirstOrDefault(c => c.Name == prop.Name); if (col != null) { JObject fieldVal = new JObject { new JProperty("dataType", col.DataType), new JProperty("value", prop.Value) }; val.Add(new JProperty(prop.Name, fieldVal)); } } model.Value = val.ToString(Newtonsoft.Json.Formatting.None); var vmData = new InfoModuleDataViewModel(model); var saveResult = await vmData.SaveModelAsync(false, _context, _transaction); result.IsSucceed = saveResult.IsSucceed; if (!result.IsSucceed) { result.Exception = saveResult.Exception; Errors.AddRange(saveResult.Errors); } } } } if (result.IsSucceed) { foreach (var navMedia in MediaNavs) { navMedia.ProductId = parent.Id; navMedia.Specificulture = parent.Specificulture; if (navMedia.IsActived) { var saveResult = await navMedia.SaveModelAsync(false, _context, _transaction); result.IsSucceed = saveResult.IsSucceed; if (!result.IsSucceed) { result.Exception = saveResult.Exception; Errors.AddRange(saveResult.Errors); } } else { var saveResult = await navMedia.RemoveModelAsync(false, _context, _transaction); result.IsSucceed = saveResult.IsSucceed; if (!result.IsSucceed) { result.Exception = saveResult.Exception; Errors.AddRange(saveResult.Errors); } } } } if (result.IsSucceed) { foreach (var navProduct in ProductNavs) { navProduct.SourceId = parent.Id; navProduct.Specificulture = parent.Specificulture; if (navProduct.IsActived) { var saveResult = await navProduct.SaveModelAsync(false, _context, _transaction); result.IsSucceed = saveResult.IsSucceed; if (!result.IsSucceed) { result.Exception = saveResult.Exception; Errors.AddRange(saveResult.Errors); } } else { var saveResult = await navProduct.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); } }
public override async Task <RepositoryResponse <bool> > SaveSubModelsAsync( SiocArticle parent , SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { bool result = true; try { var saveTemplate = await View.SaveModelAsync(false, _context, _transaction).ConfigureAwait(false); if (!saveTemplate.IsSucceed) { Errors.AddRange(saveTemplate.Errors); Exception = saveTemplate.Exception; } result = result && saveTemplate.IsSucceed; if (result) { foreach (var categoryArticleViewModel in Categories) { categoryArticleViewModel.ArticleId = Id; if (categoryArticleViewModel.IsActived) { var saveResult = await categoryArticleViewModel.SaveModelAsync(false, _context, _transaction).ConfigureAwait(false); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } else { var saveResult = await categoryArticleViewModel.RemoveModelAsync(false, _context, _transaction).ConfigureAwait(false); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } } } if (result) { foreach (var moduleArticleViewModel in Modules) { moduleArticleViewModel.ArticleId = Id; if (moduleArticleViewModel.IsActived) { var saveResult = await moduleArticleViewModel.SaveModelAsync(false, _context, _transaction).ConfigureAwait(false); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } else { var saveResult = await moduleArticleViewModel.RemoveModelAsync(false, _context, _transaction).ConfigureAwait(false); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } } } if (result) { foreach (var bEArticleModuleViewModel in ModuleNavs) { bEArticleModuleViewModel.ArticleId = Id; if (bEArticleModuleViewModel.IsActived) { var saveResult = await bEArticleModuleViewModel.SaveModelAsync(false, _context, _transaction).ConfigureAwait(false); result = saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); Exception = saveResult.Exception; } } else { var saveResult = await bEArticleModuleViewModel.RemoveModelAsync(true, _context, _transaction).ConfigureAwait(false); result = saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); Exception = saveResult.Exception; } } } } if (result) { foreach (var bEModuleViewModel in ActivedModules) { bEModuleViewModel.Data.Items = new List <InfoModuleDataViewModel>(); foreach (var data in bEModuleViewModel.Data.JsonItems) { SiocModuleData model = new SiocModuleData() { Id = data.Value <string>("id") ?? Guid.NewGuid().ToString(), Specificulture = bEModuleViewModel.Specificulture, ArticleId = Id, ModuleId = bEModuleViewModel.Id, Fields = bEModuleViewModel.Fields, CreatedDateTime = DateTime.UtcNow, UpdatedDateTime = DateTime.UtcNow }; List <ModuleFieldViewModel> cols = bEModuleViewModel.Columns; JObject val = new JObject(); foreach (JProperty prop in data.Properties()) { var col = cols.FirstOrDefault(c => c.Name == prop.Name); if (col != null) { JObject fieldVal = new JObject { new JProperty("dataType", col.DataType), new JProperty("value", prop.Value) }; val.Add(new JProperty(prop.Name, fieldVal)); } } model.Value = val.ToString(Newtonsoft.Json.Formatting.None); var vmData = new InfoModuleDataViewModel(model); var saveResult = await vmData.SaveModelAsync(false, _context, _transaction); if (saveResult.IsSucceed) { bEModuleViewModel.Data.Items.Add(vmData); } else { Errors.AddRange(saveResult.Errors); Exception = saveResult.Exception; } result = result && saveResult.IsSucceed; } } } if (result) { foreach (var navArticleMediaViewModel in MediaNavs) { if (navArticleMediaViewModel.IsActived) { navArticleMediaViewModel.ArticleId = parent.Id; var saveResult = await navArticleMediaViewModel.SaveModelAsync(false, _context, _transaction); result = saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); Exception = saveResult.Exception; } } else { navArticleMediaViewModel.ArticleId = parent.Id; var saveResult = await navArticleMediaViewModel.RemoveModelAsync(false, _context, _transaction); result = saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); Exception = saveResult.Exception; } } } } return(new RepositoryResponse <bool>() { IsSucceed = result, Data = result, Errors = Errors, Exception = Exception }); } catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only { return(new RepositoryResponse <bool>() { IsSucceed = false, Data = false, Exception = ex }); } }