示例#1
0
		public virtual ActionResult Edit(UserModel model)
		{
			if (!ModelState.IsValid) return View();

			try
			{
				_userService.Update(model);

				return RedirectToAction(MVC.User.Index(model.RoleType));
			}
			catch (DublicateLoginException)
			{
				ModelState.AddModelError("Authentication.Login", Validation.LoginExists);

				return View();
			}
		}
示例#2
0
		public virtual ActionResult Create(UserModel model)
		{
			if (string.IsNullOrWhiteSpace(model.Authentication.NewPassword))
				ModelState.AddModelError("NewPassword", Validation.EmplyPassword);

			if (!ModelState.IsValid) return View();

			try
			{
				_userService.Add(model);

				return RedirectToAction(MVC.User.Index(model.RoleType));
			}
			catch (DublicateLoginException)
			{
				ModelState.AddModelError("Authentication.Login", Validation.LoginExists);

				return View();
			}
		}
示例#3
0
		public void Add(UserModel model)
		{
			long userId;
			switch(model.RoleType)
			{
				case RoleType.Admin:
					userId = _admins.Add(model.Name, model.Authentication.Login, model.Email, TwoLetterISOLanguageName.English);
					break;

				case RoleType.Manager:
					userId = _managers.Add(model.Name, model.Authentication.Login, model.Email, TwoLetterISOLanguageName.English);
					break;

				case RoleType.Broker:
					userId = _brokers.Add(model.Name, model.Authentication.Login, model.Email, TwoLetterISOLanguageName.English);
					break;

				default:
					throw new ArgumentOutOfRangeException("model", @"Unknown role " + model.RoleType);
			}

			_users.SetPassword(userId, model.Authentication.NewPassword);
		}
示例#4
0
		public void Update(UserModel model)
		{
			long userId;
			switch(model.RoleType)
			{
				case RoleType.Admin:
					userId = _admins.Update(model.Id, model.Name, model.Authentication.Login, model.Email);
					break;

				case RoleType.Manager:
					userId = _managers.Update(model.Id, model.Name, model.Authentication.Login, model.Email);
					break;

				case RoleType.Broker:
					userId = _brokers.Update(model.Id, model.Name, model.Authentication.Login, model.Email);
					break;

				default:
					throw new ArgumentOutOfRangeException("model", @"Unknown role " + model.RoleType);
			}

			if(!string.IsNullOrEmpty(model.Authentication.NewPassword))
			{
				_users.SetPassword(userId, model.Authentication.NewPassword);
			}
		}