Ejemplo n.º 1
0
        public UpdateStaffResponse UpdateStaff(UpdateStaffRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.StaffDetail, "StaffDetail");

            var staff = PersistenceContext.Load <Staff>(request.StaffDetail.StaffRef);

            // ensure user has access to edit this staff
            CheckWriteAccess(staff);

            // if trying to associate with a new user account, check the account is free
            if (!string.IsNullOrEmpty(request.StaffDetail.UserName) && request.StaffDetail.UserName != staff.UserName)
            {
                ValidateUserNameFree(request.StaffDetail.UserName);
            }

            var assembler = new StaffAssembler();

            assembler.UpdateStaff(request.StaffDetail,
                                  staff,
                                  request.UpdateElectiveGroups && (Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.StaffGroup) || staff.UserName == this.CurrentUser),
                                  request.UpdateNonElectiveGroups && Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.StaffGroup),
                                  PersistenceContext);

            return(new UpdateStaffResponse(assembler.CreateStaffSummary(staff, PersistenceContext)));
        }
Ejemplo n.º 2
0
        public AddStaffResponse AddStaff(AddStaffRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.StaffDetail, "StaffDetail");

            // if trying to associate with a user account, check the account is free
            if (!string.IsNullOrEmpty(request.StaffDetail.UserName))
            {
                ValidateUserNameFree(request.StaffDetail.UserName);
            }

            // create new staff
            var staff = new Staff();

            // set properties from request
            var assembler = new StaffAssembler();

            var groupsEditable = Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.StaffGroup);

            assembler.UpdateStaff(request.StaffDetail,
                                  staff,
                                  groupsEditable,
                                  groupsEditable,
                                  PersistenceContext);

            PersistenceContext.Lock(staff, DirtyState.New);

            // ensure the new staff is assigned an OID before using it in the return value
            PersistenceContext.SynchState();

            return(new AddStaffResponse(assembler.CreateStaffSummary(staff, PersistenceContext)));
        }
Ejemplo n.º 3
0
		public UpdateStaffResponse UpdateStaff(UpdateStaffRequest request)
		{
			Platform.CheckForNullReference(request, "request");
			Platform.CheckMemberIsSet(request.StaffDetail, "StaffDetail");

			var staff = PersistenceContext.Load<Staff>(request.StaffDetail.StaffRef);

			// ensure user has access to edit this staff
			CheckWriteAccess(staff);

			// if trying to associate with a new user account, check the account is free
			if (!string.IsNullOrEmpty(request.StaffDetail.UserName) && request.StaffDetail.UserName != staff.UserName)
			{
				ValidateUserNameFree(request.StaffDetail.UserName);
			}

			var assembler = new StaffAssembler();
			assembler.UpdateStaff(request.StaffDetail,
				staff,
				request.UpdateElectiveGroups && (Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.StaffGroup) || staff.UserName == this.CurrentUser),
				request.UpdateNonElectiveGroups && Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.StaffGroup),
				PersistenceContext);

			return new UpdateStaffResponse(assembler.CreateStaffSummary(staff, PersistenceContext));
		}
Ejemplo n.º 4
0
		public AddStaffResponse AddStaff(AddStaffRequest request)
		{
			Platform.CheckForNullReference(request, "request");
			Platform.CheckMemberIsSet(request.StaffDetail, "StaffDetail");

			// if trying to associate with a user account, check the account is free
			if(!string.IsNullOrEmpty(request.StaffDetail.UserName))
			{
				ValidateUserNameFree(request.StaffDetail.UserName);
			}

			// create new staff
			var staff = new Staff();

			// set properties from request
			var assembler = new StaffAssembler();

			var groupsEditable = Thread.CurrentPrincipal.IsInRole(AuthorityTokens.Admin.Data.StaffGroup);
			assembler.UpdateStaff(request.StaffDetail,
				staff,
				groupsEditable,
				groupsEditable,
				PersistenceContext);

			PersistenceContext.Lock(staff, DirtyState.New);

			// ensure the new staff is assigned an OID before using it in the return value
			PersistenceContext.SynchState();

			return new AddStaffResponse(assembler.CreateStaffSummary(staff, PersistenceContext));
		}