Example #1
0
        public JsonResult AddEditAccount(AccountViewModel accountViewModel)
        {
            var accountModel = new AccountModel();
            Mapper.Map(accountViewModel, accountModel);
            Mapper.Map(accountViewModel.CountryType, accountModel.CountryModel);
            Mapper.Map(accountViewModel.AccountAccountTypes, accountModel.AccountAccountTypeModel);
            Mapper.Map(accountViewModel.AccountCategories, accountModel.AccountCategoryModel);
            Mapper.Map(accountViewModel.AccountCompanies, accountModel.AccountCompanyModel);

            //for (int i = 0; i < accountViewModel.AccountTypes.Count; i++)
            //{
            //    accountModel.AccountAccountTypeModel
            //}

            var result = new ServiceResponse();
            if (accountModel.AccountId > 0)
            {
                accountModel.AccountCategoryModel.ForEach(m => m.AccountId = accountModel.AccountId);
                accountModel.AccountAccountTypeModel.ForEach(m => m.AccountId = accountModel.AccountId);

                result = _accountService.UpdateAccountDetail(accountModel);
            }
            else
            {
                result = _accountService.SaveAccountDetail(accountModel);
            }
            AccountModel result1 = (AccountModel)result.Data;
            Mapper.Map(result1, accountViewModel);
            result.Data = accountViewModel;
            return Json(result, JsonRequestBehavior.AllowGet);
        }
Example #2
0
        public JsonResult GetAccountById(string accountId)
        {
            var accountViewModel = new AccountViewModel();
            var contacts = new List<UserViewModel>();
            //var response = new ServiceResponse();

            var accountModel = _accountService.GetAccountById(accountId.Decrypt());

            Mapper.Map(accountModel, accountViewModel);

            Mapper.Map(accountModel.AccountUserModel, accountViewModel.AccountUsers);

            for (int i = 0; i < accountModel.AccountUserModel.Count; i++)
            {
                accountViewModel.AccountUsers[i].UserViewModel = new UserViewModel();

                Mapper.Map(accountModel.AccountUserModel.ToList()[i].UserModel, accountViewModel.AccountUsers[i].UserViewModel);
                contacts.Add(accountViewModel.AccountUsers[i].UserViewModel);
            }
            Mapper.Map(accountModel.CountryModel, accountViewModel.CountryType);
            Mapper.Map(accountModel.AccountAccountTypeModel, accountViewModel.AccountAccountTypes);
            Mapper.Map(accountModel.AccountCategoryModel, accountViewModel.AccountCategories);
            Mapper.Map(accountModel.AccountCompanyModel, accountViewModel.AccountCompanies);

            if (accountViewModel != null)
            {
                return Json(new { Account = accountViewModel, Contacts = contacts, Success = true }, JsonRequestBehavior.AllowGet);

            }
            else { return Json(new { Account = accountViewModel, Success = false, Message = "No Account" }, JsonRequestBehavior.AllowGet); }
        }