コード例 #1
0
		public long Add(ClientModel client, TransitEditModel transit)
		{
			var id = _manager.Add(client, transit);

			_events.Add(id, EventType.ClientAdded, EventState.Emailing, client.Authentication.NewPassword);

			return id;
		}
コード例 #2
0
ファイル: ClientModelBinder.cs プロジェクト: UHgEHEP/test
		private static void ReadFiles(HttpRequestBase request, ClientModel model)
		{
			if (model.ContractFile == null && model.ContractFileName == null)
				request.ReadFile("ContractFile", (name, bytes) =>
				{
					model.ContractFileName = name;
					model.ContractFile = bytes;
				});
		}
コード例 #3
0
ファイル: ClientManager.cs プロジェクト: UHgEHEP/test
		public void Update(long clientId, ClientModel model, TransitEditModel transit)
		{
			var data = _clients.Get(clientId);
			var userId = data.UserId;
			var transitId = data.TransitId;

			if(!_permissions.HaveAccessToClient(data))
			{
				throw new AccessForbiddenException();
			}

			var clientEditData = GetData(model);

			Update(clientId, clientEditData, transitId, transit, userId, model.Authentication);
		}
コード例 #4
0
ファイル: ClientController.cs プロジェクト: UHgEHEP/test
		public virtual ActionResult Create(ClientModel model, [Bind(Prefix = "Transit")] TransitEditModel transitModel)
		{
			if (!EmailsHelper.Validate(model.Emails))
			{
				ModelState.AddModelError("Emails", @"Emails format is invalid");
			}

			if (!ModelState.IsValid)
			{
				BindBag(null);

				return View();
			}

			long clientId = 0;
			var passwordDefined = !string.IsNullOrWhiteSpace(model.Authentication.NewPassword);
			if (passwordDefined)
			{
				try
				{
					clientId = _manager.Add(model, transitModel);

					if (model.ContractFile != null)
					{
						MergeContract(model, clientId);
					}
				}
				catch (DublicateLoginException)
				{
					ModelState.AddModelError("Login", Validation.LoginExists);
				}
			}
			else
			{
				ModelState.AddModelError("NewPassword", Validation.EmplyPassword);
			}

			if (!ModelState.IsValid)
			{
				BindBag(null);

				return View();
			}

			return RedirectToAction(MVC.Client.Edit(clientId));
		}
コード例 #5
0
ファイル: ClientManager.cs プロジェクト: UHgEHEP/test
		public long Add(ClientModel client, TransitEditModel transit)
		{
			var data = GetData(client);

			using(var ts = new TransactionScope())
			{
				var transitId = _transits.Add(transit, null);

				var userId = _users.Add(client.Authentication.Login,
					client.Authentication.NewPassword,
					TwoLetterISOLanguageName.English);

				var clientId = _clients.Add(data, userId, transitId);

				ts.Complete();

				return clientId;
			}
		}
コード例 #6
0
ファイル: ClientController.cs プロジェクト: UHgEHEP/test
		private void ClientCantChangeDefaultSenderId(ClientModel model, ClientData client)
		{
			if (_identity.IsInRole(RoleType.Client))
			{
				model.DefaultSenderId = client.DefaultSenderId;
			}
		}
コード例 #7
0
ファイル: ClientController.cs プロジェクト: UHgEHEP/test
		private void ClientCantChangeCalculationSettings(ClientModel model, ClientData client)
		{
			if (_identity.IsInRole(RoleType.Client))
			{
				model.FactureCost = client.FactureCost;
				model.FactureCostEx = client.FactureCostEx;
				model.InsuranceRate = client.InsuranceRate;
				model.PickupCost = client.PickupCost;
				model.TransitCost = client.TransitCost;
				model.TariffPerKg = client.TariffPerKg;
				model.ScotchCostEdited = client.ScotchCostEdited;
			}
		}
コード例 #8
0
ファイル: ClientController.cs プロジェクト: UHgEHEP/test
		public virtual ActionResult Edit(long? id, ClientModel model,
			[Bind(Prefix = "Transit")] TransitEditModel transitModel)
		{
			if (!EmailsHelper.Validate(model.Emails))
			{
				ModelState.AddModelError("Emails", @"Emails format is invalid");
			}

			if (!ModelState.IsValid)
			{
				BindBag(id);

				return View();
			}

			var client = _clients.GetCurrentClientData(id);

			try
			{
				ClientCantChangeDefaultSenderId(model, client);
				ClientCantChangeCalculationSettings(model, client);

				_manager.Update(client.ClientId, model, transitModel);

				MergeContract(model, client.ClientId);
			}
			catch (DublicateLoginException)
			{
				ModelState.AddModelError("Login", Validation.LoginExists);
			}

			if (!ModelState.IsValid)
			{
				BindBag(id);

				return View();
			}

			return RedirectToAction(MVC.Client.Edit(client.ClientId));
		}
コード例 #9
0
ファイル: ClientController.cs プロジェクト: UHgEHEP/test
		private void MergeContract(ClientModel model, long clientId)
		{
			var oldFileName = _files.GetClientContractFileName(clientId);
			if (oldFileName != model.ContractFileName)
			{
				_files.SetClientContract(clientId, model.ContractFileName, model.ContractFile);
			}
		}
コード例 #10
0
		public void Update(long clientId, ClientModel model, TransitEditModel transit)
		{
			_manager.Update(clientId, model, transit);
		}
コード例 #11
0
ファイル: ClientManager.cs プロジェクト: UHgEHEP/test
		private static ClientEditData GetData(ClientModel model)
		{
			if(string.IsNullOrWhiteSpace(model.ContractDate))
			{
				throw new InvalidOperationException("ContractDate should have value");
			}

			return new ClientEditData
			{
				BIC = model.BIC,
				Phone = model.Phone,
				Emails = model.Emails,
				LegalEntity = model.LegalEntity,
				Bank = model.Bank,
				Contacts = model.Contacts,
				INN = model.INN,
				KPP = model.KPP,
				KS = model.KS,
				LegalAddress = model.LegalAddress,
				MailingAddress = model.MailingAddress,
				Nic = model.Nic,
				OGRN = model.OGRN,
				RS = model.RS,
				ContractNumber = model.ContractNumber,
				ContractDate = DateTimeOffset.Parse(model.ContractDate),
				DefaultSenderId = model.DefaultSenderId,
				FactureCost = model.FactureCost,
				FactureCostEx = model.FactureCostEx,
				InsuranceRate = model.InsuranceRate / 100,
				PickupCost = model.PickupCost,
				TransitCost = model.TransitCost,
				TariffPerKg = model.TariffPerKg,
				ScotchCostEdited = model.ScotchCostEdited,
                Comments = model.Comments
			};
		}