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;
		}
Exemple #2
0
		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;
				});
		}
Exemple #3
0
		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);
		}
Exemple #4
0
		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));
		}
Exemple #5
0
		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;
			}
		}
Exemple #6
0
		private void ClientCantChangeDefaultSenderId(ClientModel model, ClientData client)
		{
			if (_identity.IsInRole(RoleType.Client))
			{
				model.DefaultSenderId = client.DefaultSenderId;
			}
		}
Exemple #7
0
		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;
			}
		}
Exemple #8
0
		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));
		}
Exemple #9
0
		private void MergeContract(ClientModel model, long clientId)
		{
			var oldFileName = _files.GetClientContractFileName(clientId);
			if (oldFileName != model.ContractFileName)
			{
				_files.SetClientContract(clientId, model.ContractFileName, model.ContractFile);
			}
		}
		public void Update(long clientId, ClientModel model, TransitEditModel transit)
		{
			_manager.Update(clientId, model, transit);
		}
Exemple #11
0
		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
			};
		}