public ActionResult Create(CreateViewModel vmCreate) { try { if (ModelState.IsValid) { // transfer vm to dto var dtoAsset = new Asset() { AssetTypeId = DataTypeUtility.GetIntegerFromString(vmCreate.SelectedAssetTypeId), Name = vmCreate.AssetName, IsActive = true }; _unitOfWork.Assets.Add(dtoAsset); // update db _unitOfWork.CommitTrans(); // display view TempData["SuccessMessage"] = "Asset Created"; return(RedirectToAction("Create", "AssetSetting", new { assetId = dtoAsset.Id })); } TempData["ErrorMessage"] = "Unable to create record. Try again."; return(RedirectToAction("Index", "Asset")); } catch (Exception) { TempData["ErrorMessage"] = "Encountered problem"; return(RedirectToAction("Index", "Asset")); } }
public ActionResult Edit(EditViewModel vmEdit) { try { // transfer vm to dto var dtoAsset = _unitOfWork.Assets.Get(vmEdit.Id); if (dtoAsset != null) { dtoAsset.Name = vmEdit.Name; dtoAsset.AssetTypeId = DataTypeUtility.GetIntegerFromString(vmEdit.SelectedAssetTypeId); // update db _unitOfWork.CommitTrans(); // display view with message TempData["SuccessMessage"] = "Record updated."; return(RedirectToAction("Details", "Asset", new { id = vmEdit.Id })); } TempData["ErrorMessage"] = "Unable to edit record. Try again."; return(RedirectToAction("Index", "Asset")); } catch (Exception) { TempData["ErrorMessage"] = "Encountered problem"; return(RedirectToAction("Index", "Asset")); } }
public ActionResult CreateLinkedAssetTypes(int?settingTypeId) { // get messages from other controllers to display in view if (TempData["SuccessMessage"] != null) { ViewData["SuccessMessage"] = TempData["SuccessMessage"]; } try { // transfer dto to vm var dtoSettingType = _unitOfWork.AssetTypes.Get(DataTypeUtility.GetIntegerFromString(settingTypeId.ToString())); if (dtoSettingType != null) { /* * var atstLinks = _unitOfWork.AssetTypes.GetAllActive() * .Select(r => new AssetTypeSettingType(r, dtoSettingType)) * .ToList(); */ // display view //return View("CreateLinkedAssetTypes", new CreateLinkedAssetTypesViewModel(dtoSettingType, atstLinks)); return(View("CreateLinkedAssetTypes", new CreateLinkedAssetTypesViewModel())); } TempData["ErrorMessage"] = "Unable to create record. Try again."; return(RedirectToAction("Index", "SettingType")); } catch (Exception) { TempData["ErrorMessage"] = "Encountered problem"; return(RedirectToAction("Index", "SettingType")); } }
public ActionResult Create(CreateViewModel vmCreate) { try { if (!ModelState.IsValid) { TempData["ErrorMessage"] = "Problem creating record. Try again."; return(RedirectToAction("Index", "AccountTransaction")); } // transfer vm to bm var bmAssetTransaction = new Business.Models.AccountTransaction() { AssetId = DataTypeUtility.GetIntegerFromString(vmCreate.SelectedAccountId), TransactionTypeId = DataTypeUtility.GetIntegerFromString(vmCreate.SelectedTransactionTypeId), TransactionCategoryId = DataTypeUtility.GetIntegerFromString(vmCreate.SelectedTransactionCategoryId), CheckNumber = vmCreate.CheckNumber, DueDate = Convert.ToDateTime(vmCreate.DueDate), ClearDate = Convert.ToDateTime(vmCreate.ClearDate), Amount = vmCreate.Amount, Note = vmCreate.Note, }; // update db if (!_businessService.AccountTransactionService.AddTransaction(bmAssetTransaction)) { //bmAssetTransaction = _businessService.AccountTransactionService.GetTransactionOptions(vmCreate.AssetId); //vmCreate.Assets = bmAssetTransaction.AssetSelectList; //vmCreate.TransactionTypes = bmAssetTransaction.TransactionTypeSelectList; //vmCreate.TransactionCategories= bmAssetTransaction.TransactionCategorySelectList; ViewData["ErrorMessage"] = "Problem creating record"; return(View("Create", vmCreate)); } TempData["SuccessMessage"] = "Record created"; return(RedirectToAction("Details", "Account", new { Id = vmCreate.AssetId })); } catch (Exception) { TempData["ErrorMessage"] = "Encountered problem"; return(RedirectToAction("Index", "AccountTransaction")); } }
public ActionResult SelectAssetToCreate(SelectAssetToCreateViewModel vmSelectedAssetToCreate) { try { // get & validate selected id var id = DataTypeUtility.GetIntegerFromString(vmSelectedAssetToCreate.SelectedAssetId); if (id > 0) { // display view return(RedirectToAction("Create", "AccountTransaction", new { assetId = id })); } TempData["ErrorMessage"] = "Value must be selected."; return(RedirectToAction("SelectAssetToCreate", "AccountTransaction")); } catch (Exception) { TempData["ErrorMessage"] = "Encountered problem"; return(RedirectToAction("Index", "AccountTransaction")); } }
public ActionResult Edit(EditViewModel vmEdit) { try { if (!ModelState.IsValid) { TempData["ErrorMessage"] = "Problem editing record. Try again."; return(RedirectToAction("Index", "AccountTransaction")); } // transfer vm to bm var bmAssetTransaction = new Business.Models.AccountTransaction() { AssetTransactionId = vmEdit.Id, AssetId = vmEdit.AssetId, TransactionTypeId = DataTypeUtility.GetIntegerFromString(vmEdit.SelectedTransactionTypeId), TransactionCategoryId = DataTypeUtility.GetIntegerFromString(vmEdit.SelectedTransactionCategoryId), CheckNumber = vmEdit.CheckNumber, DueDate = Convert.ToDateTime(vmEdit.DueDate), ClearDate = Convert.ToDateTime(vmEdit.ClearDate), Amount = vmEdit.Amount, Note = vmEdit.Note, }; // update db if (!_businessService.AccountTransactionService.UpdateTransaction(bmAssetTransaction)) { ViewData["ErrorMessage"] = "Problem updating record"; return(View("Edit", vmEdit)); } TempData["SuccessMessage"] = "Record updated"; return(RedirectToAction("Details", "Account", new { id = vmEdit.AssetId })); } catch (Exception) { TempData["ErrorMessage"] = "Encountered Problem"; return(RedirectToAction("Index", "AccountTransaction")); } }