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 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 async Task <RepositoryResponse <bool> > SaveSubModelsAsync( SiocProduct parent , SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { bool result = true; try { // Save Template var saveTemplate = await View.SaveModelAsync(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 = await item.SaveModelAsync(false, _context, _transaction); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } else { var saveResult = await item.RemoveModelAsync(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 = await item.SaveModelAsync(false, _context, _transaction); result = result && saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); } } else { var saveResult = await item.RemoveModelAsync(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 = await item.SaveModelAsync(false, _context, _transaction); } else { var saveResult = await item.RemoveModelAsync(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 = await vmData.SaveModelAsync(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) { navMedia.ProductId = parent.Id; navMedia.Specificulture = parent.Specificulture; if (navMedia.IsActived) { var saveResult = await navMedia.SaveModelAsync(false, _context, _transaction); } else { var saveResult = await navMedia.RemoveModelAsync(false, _context, _transaction); result = saveResult.IsSucceed; if (!result) { Errors.AddRange(saveResult.Errors); Exception = saveResult.Exception; } } } } if (result) { foreach (var navProduct in ProductNavs) { navProduct.SourceProductId = parent.Id; navProduct.Specificulture = parent.Specificulture; navProduct.CreatedBy = parent.CreatedBy; if (navProduct.IsActived) { var saveResult = await navProduct.SaveModelAsync(false, _context, _transaction); } else { var saveResult = await navProduct.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 { result = false; return(new RepositoryResponse <bool>() { IsSucceed = false, Data = false, Exception = ex }); } }