예제 #1
0
		public void SaveClientUser(int userId, ClientUserViewModel model)
		{
			if (model == null) throw new ArgumentNullException("model");

			var company = _clientCompanyManager.GetClientCompanyById(model.CompanyID);
			var branch = _clientBranchManager.GetClientBranchById(model.BranchID);
			var clientUser = _clientUserManager.GetByUserId(userId);
			clientUser.User.FirstName = model.User.FirstName;
			clientUser.User.LastName = model.User.LastName;
			clientUser.Status = model.Status;
			clientUser.PhoneNumber = model.PhoneNumber;
			clientUser.IsViewAllCompanyOrders = model.IsViewAllCompanyOrders;
			if (clientUser.Branch == null || clientUser.Branch.Id != branch.Id)
			{
				clientUser.Branch = branch;
			}
			if (clientUser.Company == null || clientUser.Company.Id != company.Id)
			{
				clientUser.Company = company;
			}

			if (clientUser.User.PrimaryRole.RoleType != model.RoleType)
			{
				clientUser.User.Roles.Remove(clientUser.User.PrimaryRole);
				clientUser.User.Roles.Add(_referenceManagement.GetRoleWithoutCache(model.RoleType));
			}

			_clientUserManager.Update(clientUser);
		}
예제 #2
0
		public void CreateClientUser(ClientUserViewModel model)
		{
			if (model == null) throw new ArgumentNullException("model");
			if (_userManagement.IsExistsUser(model.User.Email)) throw new Exception(string.Format("User with email {0} already exists", model.User.Email));

			var user = _userManagement.CreateUser(model.User, model.RoleType);
			var company = _clientCompanyManager.GetClientCompanyById(model.CompanyID);
			var branch = _clientBranchManager.GetClientBranchById(model.BranchID);

			var clientUser = new ClientUser();
			clientUser.User = user;
			clientUser.Branch = branch;
			clientUser.Company = company;
			clientUser.Status = model.Status;
			clientUser.PhoneNumber = model.PhoneNumber;
			clientUser.IsViewAllCompanyOrders = model.IsViewAllCompanyOrders;

			_clientUserManager.CreateUser(clientUser);
		}
예제 #3
0
		public ClientUserViewModel GetClientUserById(int userId)
		{
			if (!_clientUserAccessManager.IsOtherUserDataAvailable(userId))
				throw new SecurityException(string.Format("Access for user {0} denied", _clientUserAccessManager.CurrentUserEmail));

			var clientUser = _clientUserManager.GetByUserId(userId);
			clientUser.IsUserLocked = _userManagement.CheckFailedAttempts(clientUser.User.Email) == FailedAttemptResult.Locked;
			var model = new ClientUserViewModel(clientUser, _referenceManagement.FindState(clientUser.Company.Profile.Address.State), _referenceManagement.FindState(clientUser.Branch.Address.State));

			return model;
		}
예제 #4
0
		public ActionResult GetClientUserRoles(int companyId)
		{
			ClientUserViewModel model = new ClientUserViewModel();
			model.Company = _clientCompanyService.GetClientCompanyInfo(companyId);

			Dictionary<string, string> roles = GetClientUserRoles(model.Company);
			ViewBag.ClientUserRoles = new SelectList(roles.AddEmptyItem("0"), "Key", "Value", "0");

			return PartialView(Constants.Views.ClientUserRole, model);
		}
예제 #5
0
		public ActionResult GetClientCompanyInfo(int companyId, int? branchId, int? currentBranchId, int? role, bool isEdit, bool isCompanyReadonly)
		{
			var clientComapny = _clientCompanyService.GetClientCompanyInfo(companyId);
			var clientUser = new ClientUserViewModel();
			clientUser.Company = clientComapny;

			if (clientComapny != null)
			{
				clientUser.CompanyID = clientComapny.Id;
				clientUser.CompanyName = clientComapny.CompanyName;

				if (branchId.HasValue && branchId.Value != 0)
				{
					var clientBranch = _clientBranchService.GetBranche(clientComapny.CompanyId, branchId.ToString());
					clientUser.Branch = clientBranch;
					clientUser.BranchID = SafeConvert.ToInt(clientBranch.Id, 0);
				}

				var branches = _clientBranchService.GetBranches(new BranchesFilter()
				{
					CompanyId = clientComapny.CompanyId,
					ItemsPerPage = Int32.MaxValue,
					PageNumber = 1,
					ColumnName = BranchesColumnName.BranchName,
					IsAsc = true
				}).Where(b => b.Status == ClientCompanyBrancheStatus.Active || b.Id == currentBranchId.SafeToString(true)).ToDictionary(k => k.Id, v => v.BranchName);
				if (!isEdit)
				{
					branches = branches.AddEmptyItem("0").ToDictionary(k => k.Key, v => v.Value);
				}

				ViewBag.ClientUserBranches = new SelectList(branches, "Key", "Value", (branchId ?? 0).ToString());
			}

			Dictionary<string, string> roles = GetClientUserRoles(clientComapny);
			ViewBag.ClientUserRoles = new SelectList(roles.AddEmptyItem("0"), "Key", "Value", (role ?? 0).ToString());
			clientUser.RoleTypeId = role ?? 0;

			ViewBag.IsRoleStatusAndBranchEditable = IsRoleStatusAndBranchEditable();

			ViewBag.IsEdit = isEdit;
			ViewBag.IsCompanyReadonly = isCompanyReadonly;
			return PartialView(Constants.Views.ClientUserCompanyInfo, clientUser);
		}
예제 #6
0
		private ClientUserViewModel GetClientUserViewModel()
		{
			var clientUser = new ClientUserViewModel();
			clientUser.User = new UserViewModel();
			clientUser.User.Email = "*****@*****.**";
			clientUser.Status = ClientUserStatus.Active;
			clientUser.BranchID = 1;

			return clientUser;
		}
예제 #7
0
		public ActionResult Index(int? userId)
		{
			ViewBag.IsEdit = userId.HasValue;
			ViewBag.IsCompanyReadonly = userId.HasValue;
			ClientUserViewModel model = TempData[_clientUserDetailsKey] as ClientUserViewModel;

			if (model == null)
			{
				if (userId.HasValue)
				{
					model = _clientUserService.GetClientUserById(userId.Value);
				}
				else
				{
					model = new ClientUserViewModel();

					if (SecurityContext.CurrentUser.HasUserAnyRoles(RoleType.ClientAdmin, RoleType.SuperUser, RoleType.UserAdministrator))
					{
						ViewBag.IsCompanyReadonly = true;
						var currentClientUser = _clientUserService.GetClientUserByEmail(User.Identity.Name);
						model.CompanyID = currentClientUser.Company.Id;
						model.CompanyName = currentClientUser.Company.CompanyName;
						model.Company = new ClientCompanyViewModel(currentClientUser.Company, _referenceManagement.FindState(currentClientUser.Company.Profile.Address.State));
					}
				}
			}
			else if (model.BranchID.Equals(default(int)))
			{
				ViewBag.ErrorMessage = "User’s affiliation with Branch is required to finish user's creation process.";
			}
			model.UserId = userId;

			var currentRole = model.RoleTypeId.ToString();
			Dictionary<string, string> roles = new Dictionary<string, string>();
			if (model.Company != null)
			{
				if (model.Company.IsLender || model.Company.IsOtherBusinessType)
				{
					roles = _referenceManagement.GetLenderAndOtherCompanyRolesForClientUsers();
				}
				else if (model.Company.IsBroker)
				{
					roles = _referenceManagement.GetBrokerCompanyRolesForClientUsers();
				}
				else if (model.Company.IsAppraiserManagementCompany)
				{
					roles = _referenceManagement.GetAppraiserManagementCompanyRolesForClientUsers();
				}
			}

			IDictionary<ClientUserStatus, string> statuses = null;

			if (userId.HasValue)
			{
				statuses = _referenceManagement.GetStatusesForClientUser(model.Status);
				roles = roles.MakeCurrentValue<string>(currentRole);
				statuses = statuses.MakeCurrentValue<ClientUserStatus>(model.Status);
			}
			else
			{
				statuses = _referenceManagement.GetClientUserStatuses();
			}

			ViewBag.ClientUserRoles = new SelectList(roles.AddEmptyItem("0"), "Key", "Value", currentRole);
			ViewBag.ClientUserStatuses = new SelectList(statuses, "Key", "Value", model.Status);

			if (model.Company != null)
			{
				var branches = _clientBranchService.GetBranches(new BranchesFilter()
				{
					CompanyId = model.Company.CompanyId,
					ItemsPerPage = Int32.MaxValue,
					PageNumber = 1,
					ColumnName = BranchesColumnName.BranchName,
					IsAsc = true
				}).Where(e => e.Status == ClientCompanyBrancheStatus.Active || (model.Branch != null && model.Branch.Id == e.Id)).ToDictionary(k => k.Id, v => v.BranchName);
				ViewBag.ClientUserBranches = new SelectList(branches, "Key", "Value");
			}

			if (userId.HasValue && string.Equals(User.Identity.Name, model.User.Email, StringComparison.OrdinalIgnoreCase))
			{
				ViewBag.SectionTitle = "Your Profile";
				ViewBag.Title = "DVS - Your Profile";
				ViewBag.IsProfile = true;
			}
			else
			{
				ViewBag.SectionTitle = userId.HasValue ? String.Format("Client User Details - {0} {1}", model.User.FirstName, model.User.LastName) : "Add Client User";
				ViewBag.Title = userId.HasValue ? "DVS - Client User Details" : "DVS - Add Client User";
				ViewBag.IsProfile = false;
			}

			ViewBag.IsRoleStatusAndBranchEditable = IsRoleStatusAndBranchEditable(userId);
			ViewBag.IsClientUserStatusEditable = IsClientUserStatusEditable(userId);
			ViewBag.IsViewAllCompanyOrdersCheckboxVisible = IsViewAllCompanyOrdersCheckboxVisible();

			return View(model);
		}
예제 #8
0
		public ActionResult SaveClientUser(ClientUserViewModel model, bool toRedirect = false)
		{
			if (ModelState.IsValid)
			{
				if (model.UserId.HasValue)
				{
					if (!IsRoleStatusAndBranchEditable(model.UserId))
					{
						var loadedModel = _clientUserService.GetClientUserById(model.UserId.Value);
						model.RoleType = loadedModel.RoleType;
						model.BranchID = loadedModel.BranchID;
						model.Status = loadedModel.Status;
					}
					_clientUserService.SaveClientUser(model.UserId.Value, model);
				}
				else
				{
					_clientUserService.CreateClientUser(model);
				}


				CommitProviderInstance.Commit();

				if (!toRedirect)
				{
					return RedirectToAction(NameHelper.ClientUserDetails.Index);
				}

				return RedirectToAction(NameHelper.ClientUserPipeline.Index, NameHelper.ClientUserPipeline.Controller, NameHelper.ClientUserPipeline.Area);
			}

			TempData[_clientUserDetailsKey] = model;

			return RedirectToAction("Index", new { userId = model.UserId });
		}