public CreditApplicationViewModel GetNewCreditApplicationViewModel(ClientGroup clientGroup) { var result = new CreditApplicationViewModel(); result.ClientGroupViewModel = new ClientGroupViewModel(clientGroup); result.CreditCategoryViewModel = new CreditCategoryViewModel(); result.CreditCategoryViewModel.SelectedCreditCategoryId = Guid.Empty; switch (clientGroup) { case ClientGroup.PrivatePerson: result.CreditCategoryViewModel = creditCategoryManager.GetCreditCategoryDropDownListViewModel(ClientGroup.PrivatePerson); break; case ClientGroup.SmallBusiness: result.CreditCategoryViewModel = creditCategoryManager.GetCreditCategoryDropDownListViewModel(ClientGroup.SmallBusiness); break; case ClientGroup.CorporateClient: result.CreditCategoryViewModel = creditCategoryManager.GetCreditCategoryDropDownListViewModel(ClientGroup.CorporateClient); break; default: throw new ArgumentException(); } return(result); }
private static void FillCreditApplicationViewModel(CreditApplicationViewModel viewModel) { viewModel.RegisterDate = DateTime.Now; viewModel.IsCompleted = false; viewModel.CompleteDate = null; viewModel.Outcome = null; viewModel.RejectionReason = null; }
public ActionResult Create([Bind(Include = "ClientGroupViewModel,CreditCategoryViewModel,ClientId")] CreditApplicationViewModel viewModel, IEnumerable <HttpPostedFileBase> attachments) { try { if (!Request.IsAuthenticated || !User.IsInRole("Operator")) { throw new BusinessException("You don't have permissions for this operation"); } creditApplicationManager.SaveNewCreditApplication(viewModel, attachments); return(RedirectToAction("List", "Application")); } catch (BusinessException e) { TempData["ErrorMessage"] = e.Message; return(RedirectToAction("Create", "Application", new { clientGroupId = (int)viewModel.ClientGroupViewModel.SelectedClientGroup })); } }
public void SaveNewCreditApplication(CreditApplicationViewModel viewModel) { Contract.NotNull(viewModel, "CreditApplicationViewModel cannot be null"); Contract.NotNull(viewModel.ClientGroupViewModel, "ClientGroupViewModel cannot be null"); Contract.NotNull(viewModel.CreditCategoryViewModel, "CreditCategoryViewModel cannot be null"); Contract.NotEmptyGuid(viewModel.CreditCategoryViewModel.SelectedCreditCategoryId, "SelectedCreditCategoryId cannot be empty"); Contract.NotEmptyGuid(viewModel.ClientId, "ClientId cannot be empty"); viewModel.RegisterDate = DateTime.Now; viewModel.IsCompleted = false; viewModel.CompleteDate = null; viewModel.Outcome = null; viewModel.RejectionReason = null; var entity = AutoMapper.Mapper.Map <CreditApplication>(viewModel); unitOfWork.GetRepository <CreditApplication>().InsertOrUpdate(entity); unitOfWork.Commit(); }
public bool SaveNewCreditApplication(CreditApplicationViewModel viewModel) { Contract.NotNull(viewModel, "CreditApplicationViewModel cannot be null"); Contract.NotNull(viewModel.ClientGroupViewModel, "ClientGroupViewModel cannot be null"); Contract.NotNull(viewModel.CreditCategoryViewModel, "CreditCategoryViewModel cannot be null"); Contract.NotEmptyGuid(viewModel.CreditCategoryViewModel.SelectedCreditCategoryId, "SelectedCreditCategoryId cannot be empty"); Contract.NotEmptyGuid(viewModel.ClientId, "ClientId cannot be empty"); if (IsCreditApplicationAlreadyExistsForClient(viewModel.ClientId)) { return(false); } FillCreditApplicationViewModel(viewModel); var entity = AutoMapper.Mapper.Map <CreditApplication>(viewModel); unitOfWork.GetRepository <CreditApplication>().InsertOrUpdate(entity); unitOfWork.Commit(); taskManager.CreateTaskForNewCreditApplication(entity); return(true); }
public void SaveNewCreditApplication(CreditApplicationViewModel viewModel, IEnumerable <HttpPostedFileBase> attachments) { Contract.NotNull(viewModel, "CreditApplicationViewModel cannot be null"); Contract.NotNull(viewModel.ClientGroupViewModel, "ClientGroupViewModel cannot be null"); Contract.NotNull(viewModel.CreditCategoryViewModel, "CreditCategoryViewModel cannot be null"); Contract.NotEmptyGuid(viewModel.CreditCategoryViewModel.SelectedCreditCategoryId, "SelectedCreditCategoryId cannot be empty"); Contract.NotEmptyGuid(viewModel.ClientId, "ClientId cannot be empty"); if (IsCreditApplicationAlreadyExistsForClient(viewModel.ClientId)) { throw new BusinessException("Application for this client already exists"); } FillCreditApplicationViewModel(viewModel); var entity = AutoMapper.Mapper.Map <CreditApplication>(viewModel); unitOfWork.GetRepository <CreditApplication>().InsertOrUpdate(entity); unitOfWork.Commit(); AddAttachments(entity.Id, attachments); taskManager.CreateTasksForNewCreditApplication(entity); }