public async Task <IActionResult> EditModuleData(InfoModuleDataViewModel ModuleData) { if (ModelState.IsValid) { try { var result = await ModuleData.SaveModelAsync(); if (result.IsSucceed) { return(RedirectToAction("Details", new RouteValueDictionary( new { id = ModuleData.ModuleId }))); } else { ModelState.AddModelError(string.Empty, result.Exception.Message); return(View(ModuleData)); } } catch (DbUpdateConcurrencyException) { if (!InfoModuleDataViewModel.Repository.CheckIsExists(m => m.Id == ModuleData.Id)) { return(NotFound()); } else { throw; } } //return RedirectToAction("Index"); } return(View(ModuleData)); }
public async Task <IActionResult> AjaxSaveModuleData(InfoModuleDataViewModel ModuleData) { if (ModelState.IsValid) { ModuleData.CreatedDateTime = DateTime.UtcNow; var result = await ModuleData.SaveModelAsync(); if (result.IsSucceed) { return(PartialView("_ModuleData_Record", result.Data)); } else { throw new Exception(result.Exception.StackTrace); } } return(View(ModuleData)); }
public async Task <IActionResult> AddModuleData(InfoModuleDataViewModel ModuleData) { if (ModelState.IsValid) { ModuleData.CreatedDateTime = DateTime.UtcNow; var result = await ModuleData.SaveModelAsync(); if (result.IsSucceed) { return(RedirectToAction("Details", new RouteValueDictionary(new { id = ModuleData.ModuleId }))); } else { throw new Exception(result.Exception.StackTrace); } } return(View(ModuleData)); }
public async Task <InfoModuleDataViewModel> AjaxAddModuleData(int moduleId) { string _lang = RouteData.Values["culture"].ToString(); var module = await BEModuleViewModel.Repository.GetSingleModelAsync( m => m.Id == moduleId && m.Specificulture == _lang); if (module.IsSucceed) { var ModuleData = new InfoModuleDataViewModel() { Id = Guid.NewGuid().ToString("N"), ModuleId = moduleId, Specificulture = _lang, Fields = module.Data?.Fields }; return(ModuleData); } else { return(null); } }
public async Task <IActionResult> AddModuleData(int id) { var getModule = await InfoModuleViewModel.Repository.GetSingleModelAsync( m => m.Id == id && m.Specificulture == CurrentLanguage); if (getModule.IsSucceed) { var module = getModule.Data; var ModuleData = new InfoModuleDataViewModel( new SiocModuleData() { Id = Guid.NewGuid().ToString("N"), ModuleId = id, Specificulture = CurrentLanguage, Fields = module.Fields }); return(View(ModuleData)); } else { return(NotFound()); } }
public Task <RepositoryResponse <InfoModuleDataViewModel> > Save([FromBody] JObject data) { var model = data["model"].ToObject <SiocModuleData>(); List <ModuleFieldViewModel> cols = data["columns"].ToObject <List <ModuleFieldViewModel> >(); JObject val = new JObject(); foreach (JProperty prop in data.Properties()) { if (prop.Name != "model" && prop.Name != "columns") { var col = cols.Find(c => c.Name == prop.Name); 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); return(vmData.SaveModelAsync()); }
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 }); } }