public async Task <IActionResult> AddEditAsset(AddEditAssetViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var errorText = await _assetService.AddOrUpdate(model); if (string.IsNullOrWhiteSpace(errorText)) { return(RedirectToAction("Assets")); } ModelState.AddModelError("", errorText); return(View(model)); }
public async Task <string> AddOrUpdate(AddEditAssetViewModel model) { model.Name = model.Name.Trim(); model.Description = model.Description.Trim(); model.Columns = model.Columns.Trim(); var asset = await _assetRepository.GetOne(model.Name); if (asset == null) { if (model.IsNew) { asset = new AssetEntity { Key = model.Name } } ; else { return("Asset not found."); } } else if (model.IsNew) { return("Asset already exists."); } var columns = model.Columns.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList(); if (columns.Count < 2) { return("There should be at least 2 columns separated by comma."); } asset.Description = model.Description; asset.Columns = string.Join(",", columns); await _assetRepository.AddOrUpdate(asset); return(string.Empty); }
public async Task <IActionResult> AddEditAsset(string assetName) { var model = new AddEditAssetViewModel { IsNew = true }; if (string.IsNullOrWhiteSpace(assetName)) { return(View(model)); } model = await _assetService.GetAssetDetails(assetName); if (model == null) { ModelState.AddModelError("name", "Asset not found."); } else { model.IsNew = false; } return(View(model)); }