Example #1
0
		public async Task UpdateUser(User user)
		{
			var existingUser = await this.GetUserByIdInner(user.Id);

			if (existingUser == null)
			{
				throw new ArgumentException("Could not locate User with Id " + user.Id);
			}

			UserService.MergeUserInstances(sourceUser: user, targetUser: existingUser);

			await this.doorAccessService.UpdateUser(existingUser);
		}
Example #2
0
		public async Task UpdateUser(User existingUser)
		{
			await Task.Run(() =>
			{
				try
				{
					using (var client = this.GetNewClient())
					{
						var userId = existingUser.Id;
						//var existingUserView = this.GetUserViews(client, item => item.UserId == userId).SingleOrDefault();
						var existingUserView = this.GetUserViews(client, "UserId = " + userId).SingleOrDefault();

						if (existingUserView == null)
						{
							throw new ArgumentException("Could not find User with Id " + userId);
						}

						var writeableUserView = new WriteableUserView(existingUserView);
						writeableUserView.FirstName = existingUser.FirstName;
						writeableUserView.Surname = existingUser.Surname;

						bool operationResult = this.UpdateUserView(client, writeableUserView);

						if (!operationResult)
						{
							throw new InvalidOperationException("UpdateUserRecord returned false.  This might mean the operation didn't complete correctly.");
						}
					}
				}
				catch (Exception e)
				{
					// TODO: log here
					// TODO: wrap and rethrow exception
					throw;
				}
			});
		}
Example #3
0
		public async Task CreateUser(User user)
		{
			await Task.Run(() =>
			{
				try
				{
					using (var client = this.GetNewClient())
					{
						var departmentsById = client.ViewDepartments().DepartmentsDictionary();
						var departmentMatches = departmentsById.Where(pair => pair.Value == user.Department);

						if (departmentMatches.Count() != 1)
						{
							throw new InvalidOperationException("Could not find user's department " + user.Department);
						}

						var operationResult =
							client.AddUserRecord(
								accessLevelId: this.net2OxHackAccessLevelId,
								departmentId: departmentMatches.Single().Key,
								antiPassbackInd: false,
								alarmUserInd: false,
								firstName: (user.FirstName ?? String.Empty).Trim(),
								middleName: String.Empty,
								surname: (user.Surname ?? String.Empty).Trim(),
								telephoneNo: String.Empty,
								telephoneExtension: String.Empty,
								pinCode: String.Empty,
								pictureFileName: String.Empty,
								activationDate: DateTime.Now,
								cardNumber: 0,
								cardTypeId: 0,
								active: true,
								faxNo: String.Empty,
								expiryDate: DateTime.MinValue,
								customFields: null);

						if (!operationResult)
						{
							throw new InvalidOperationException("AddUserRecord returned false.  This might mean the operation didn't complete correctly.");
						}
					}
				}
				catch (Exception e)
				{
					// TODO: log here
					// TODO: wrap and rethrow exception
					throw;
				}
			});
		}
Example #4
0
		private static void MergeUserInstances(User sourceUser, User targetUser)
		{
			targetUser.FirstName = sourceUser.FirstName ?? targetUser.FirstName;
			targetUser.Surname = sourceUser.Surname ?? targetUser.Surname;
			targetUser.Cards = sourceUser.Cards ?? targetUser.Cards;
		}
Example #5
0
		public async Task CreateUser(User user)
		{
			if (String.IsNullOrWhiteSpace(user.FirstName) && String.IsNullOrWhiteSpace(user.Surname))
			{
				throw new BusinessRuleException("User must have at least a FirstName or a Surname.");
			}

			user.Department = this.oxhackDepartmentName;

			await this.doorAccessService.CreateUser(user);
		}