Example #1
0
		public void Update(long id, SenderModel model)
		{
			if(model.TariffOfTapePerBox < 0)
			{
				throw new InvalidDataException("TariffOfTapePerBox can't be less than 0.");
			}

			var data = _senders.Get(id);

			data.Name = model.Name;
			data.Login = model.Authentication.Login;
			data.Email = model.Email;
			data.TariffOfTapePerBox = model.TariffOfTapePerBox;
			data.Contact = model.Contact;
			data.Phone = model.Phone;
			data.Address = model.Address;

			_senders.Update(id, data);

			_senders.SetCountries(id, model.Countries);

			if(!string.IsNullOrWhiteSpace(model.Authentication.NewPassword))
			{
				var userId = _senders.GetUserId(id);

				_users.SetPassword(userId, model.Authentication.NewPassword);
			}
		}
Example #2
0
		public virtual ActionResult Edit(long id, SenderModel model)
		{
			try
			{
				if(ModelState.IsValid)
				{
					_senders.Update(id, model);

					return RedirectToAction(MVC.Sender.Edit(id));
				}
			}
			catch(DublicateLoginException)
			{
				ModelState.AddModelError("Authentication.Login", Validation.LoginExists);				
			}

			BindBag();

			return View();
		}
Example #3
0
		private static void VerifyData(SenderModel model)
		{
			using(var connection = new SqlConnection(Settings.Default.MainConnectionString))
			{
				connection.Open();

				var actual = connection.Query<SenderData>(
					"select u.Login, s.Name, s.Email, s.TariffOfTapePerBox, s.Contact, s.Phone, s.Address from [dbo].[sender] s "
					+ "join [dbo].[user] u on s.userid = u.id where u.login = @login",
					new { model.Authentication.Login }).First();

				actual.ShouldBeEquivalentTo(model, options => options.ExcludingMissingProperties());

				var countries = connection.Query<long>(
					"select c.[CountryId] from [dbo].[SenderCountry] c "
					+ "join [dbo].[sender] s on s.[id] = c.[SenderId] "
					+ "join [dbo].[user] u on s.userid = u.id where u.login = @login",
					new { model.Authentication.Login }).ToArray();

				model.Countries.ShouldBeEquivalentTo(countries);
			}
		}
Example #4
0
		public virtual ActionResult Create(SenderModel model)
		{
			if(string.IsNullOrWhiteSpace(model.Authentication.NewPassword))
				ModelState.AddModelError("NewPassword", Validation.EmplyPassword);

			try
			{
				if(ModelState.IsValid)
				{
					var id = _senders.Add(model);

					return RedirectToAction(MVC.Sender.Edit(id));
				}
			}
			catch(DublicateLoginException)
			{
				ModelState.AddModelError("Authentication.Login", Validation.LoginExists);
			}

			BindBag();

			return View();
		}
Example #5
0
		public long Add(SenderModel model)
		{
			if(model.TariffOfTapePerBox < 0)
			{
				throw new InvalidDataException("TariffOfTapePerBox can't be less than 0.");
			}

			var id = _senders.Add(new SenderData
			{
				Email = model.Email,
				Login = model.Authentication.Login,
				Name = model.Name,
				TariffOfTapePerBox = model.TariffOfTapePerBox,
				Language = TwoLetterISOLanguageName.English,
				Contact = model.Contact,
				Phone = model.Phone,
				Address = model.Address
			},
				model.Authentication.NewPassword);

			_senders.SetCountries(id, model.Countries);

			return id;
		}