Пример #1
0
		public ActionResult SaveLetter(ClientCompanyLetterViewModel viewModel, InstructionViewModel instructionsCollection)
		{
			if (ModelState.IsValid)
			{
				var itemToValidate = instructionsCollection.LenderInstructions.SingleOrDefault(e => e.IsEditable);

				if (itemToValidate != null)
				{
					if (!instructionsCollection.LenderInstructions.Any(i => string.IsNullOrWhiteSpace(i.Text)))
					{
						ViewBag.NotificationMessage = itemToValidate.IsNew ? Constants.Notifications.InstructionSaved : Constants.Notifications.InstructionUpdated;
						_clientCompanyLetterService.SaveInstruction(itemToValidate, instructionsCollection.CompanyId);
						itemToValidate.IsEditable = false;
						CommitProviderInstance.Commit();
					}
					else
					{
						instructionsCollection.AlertMessage = Constants.ErrorMessages.InstructionEmptyText;
					}
				}

				viewModel.InstructionsCollection = instructionsCollection;
				_clientCompanyLetterService.SaveClientCompanyLetter(viewModel, PluginResults.Find<UserAccessPluginResult>().CompnayId);
				CommitProviderInstance.Commit();

				return PluginResults.Plugins<CurrentMenuPluginResule>().GetRedirectToTab();
			}

			return View();
		}
Пример #2
0
		public void SaveClientCompanyLetter(ClientCompanyLetterViewModel viewModel, string clientCompanyId)
		{
			var company = _clientCompanyManagement.FindById(clientCompanyId);
			if (company == null)
				throw new ArgumentNullException("company not found");
			_clientCompanyManagement.SaveClientCompanyLetter(company, viewModel);
		}
Пример #3
0
		public void SaveClientCompanyLetter(ClientCompany company, ClientCompanyLetterViewModel viewModel)
		{
			if (company == null)
				throw new ArgumentNullException("company");

			var companyInstructions = company.CompanyInstructions;
			var newInstructions = GetLenderSpecialInstructions(viewModel);

			if (companyInstructions == null)
				companyInstructions = new Collection<ClientCompanyInstruction>();

			var specInstructions = companyInstructions.Where(c => c.ReferenceId.HasValue).ToList();
			if (newInstructions.Count > 0)
			{
				for (int i = 0; i < specInstructions.Count; i++)
				{
					if (newInstructions.Select(a => a.Id).Contains(specInstructions[i].ReferenceId.Value))
						continue;
					companyInstructions.Remove(specInstructions[i]);
					newInstructions.Remove(specInstructions[i]);
				}

				foreach (var clientCompanyInstruction in newInstructions)
				{
					companyInstructions.Add(new ClientCompanyInstruction
					{
						ReferenceId = clientCompanyInstruction.ReferenceId,
						Text = clientCompanyInstruction.Text
					});
				}
			}
			else
			{
				foreach (var spec in specInstructions)
				{
					companyInstructions.Remove(spec);
				}
			}
		}
Пример #4
0
		private static ClientCompanyLetterViewModel GetModel(ClientCompany company)
		{
			var viewModel = new ClientCompanyLetterViewModel
			{
				InstructionsCollection = new InstructionViewModel { LenderInstructions = new List<InstructionItemViewModel>(), CompanyId = company.CompanyId },
				Specialnstructions = new List<int>(),
			};
			if (company.CompanyInstructions == null)
				return viewModel;

			foreach (var instruction in company.CompanyInstructions)
			{
				if (instruction.ReferenceId.HasValue)
				{
					viewModel.Specialnstructions.Add(instruction.ReferenceId.Value);
				}
				else
				{
					viewModel.InstructionsCollection.LenderInstructions.Add(new InstructionItemViewModel { Id = instruction.Id.ToString(), Text = instruction.Text });
				}
			}

			return viewModel;
		}
Пример #5
0
		private List<ClientCompanyInstruction> GetLenderSpecialInstructions(ClientCompanyLetterViewModel viewModel)
		{
			var instructions = new List<ClientCompanyInstruction>();
			if (viewModel.Specialnstructions != null)
			{
				foreach (var instructionId in viewModel.Specialnstructions)
				{
					int id = instructionId;
					var instr = _referenceRepository.GetLenderSpecialInstructions().First(s => s.Id == id);
					instructions.Add(new ClientCompanyInstruction { ReferenceId = id, Text = instr.DisplayName });
				}
			}
			return instructions;
		}