public ActionResult Index() { var model = new AccountCodeViewModel(); var accountCodes = new List <AccountCodeViewModel>(); var tempCodes = _accountCodeRepository.GetAccountCodes(); foreach (var tempCode in tempCodes) { AccountCodeViewModel convertedModel = new AccountCodeConverter().ConvertToView(tempCode); accountCodes.Add(convertedModel); } model.AccountCodes = accountCodes.OrderBy(x => x.Description).ToList(); model.SelectableCustomers = _customerDynamicsRepository.GetSelectableCustomers(); var defaultCustomer = new SelectListItem() { Text = "--Select Customer--", Value = null }; model.SelectableCustomers.Insert(0, defaultCustomer); model.SelectableBuckets = _bucketRepository.GetSelectableBuckets(); return(View(model)); }
public JsonResult EditAccountCode(AccountCodeViewModel model) { var operationResult = new OperationResult(); AccountCode code = new AccountCodeConverter().ConvertToDomain(model); operationResult = _accountCodeRepository.UpdateAccountCode(code); if (operationResult.Success) { model.Success = true; var accountCodes = new List <AccountCodeViewModel>(); var tempCodes = _accountCodeRepository.GetAccountCodes(); foreach (var tempCode in tempCodes) { AccountCodeViewModel convertedModel = new AccountCodeConverter().ConvertToView(tempCode); accountCodes.Add(convertedModel); } model.AccountCodes = accountCodes.OrderBy(x => x.Description).ToList(); } else { model.Success = false; model.Message = operationResult.Message; } return(Json(model, JsonRequestBehavior.AllowGet)); }
/// <summary> /// convert accountCode to view model /// </summary> /// <param name="code"></param> /// <returns></returns> public AccountCodeViewModel ConvertToView(AccountCode code) { AccountCodeViewModel model = new AccountCodeViewModel(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _bucketRepository = new BucketRepository(); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(code.CustomerId); var bucket = _bucketRepository.GetBucket(code.AccountCodeId); model.AccountCodeId = code.AccountCodeId; model.Description = (!string.IsNullOrEmpty(code.Description)) ? code.Description : "N/A"; model.CustomerId = code.CustomerId; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.BucketName = (bucket != null && !string.IsNullOrEmpty(bucket.Name)) ? bucket.Name : "N/A"; if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_bucketRepository != null) { _bucketRepository.Dispose(); _bucketRepository = null; } return(model); }
/// <summary> /// convert AccountCode view model to domain /// </summary> /// <param name="model"></param> /// <returns></returns> public AccountCode ConvertToDomain(AccountCodeViewModel model) { AccountCode code = new AccountCode(); code.AccountCodeId = model.AccountCodeId; code.Description = model.Description; code.CustomerId = model.CustomerId; return(code); }