public void ChangeActivationDepartment()
        {
            Department depart = new Department(0, Name, Description, true);

            depart.Activate();
            Assert.IsTrue(depart.Active);
            depart.Deactivate();
            Assert.IsFalse(depart.Active);
        }
예제 #2
0
        public async Task <Unit> Handle(CreateDepartmentCommand request, CancellationToken cancellationToken)
        {
            var user   = _userAccessor.GetUser();
            var userId = Guid.Parse(_userAccessor.GetUser().FindFirst(ClaimTypes.NameIdentifier).Value);

            var department = new Department
            {
                Name             = request.Name,
                Description      = request.Description,
                BusinessUnitId   = request.BusinessUnitId,
                DepartmentLeadId = request.DepartmentLeadId,
                Abbreviation     = request.Abbreviation
            };

            department.CreateEnd(Guid.NewGuid(), request.Name, userId);

            if (request.Active)
            {
                department.Activate();
            }
            else
            {
                department.Deactivate();
            }

            _context.Departments.Add(department);

            await _context.SaveChangesAsync(cancellationToken);


            var notification = new DepartmentCreated()
            {
                PrimaryEntityId   = department.Id,
                PrimaryEntityName = department.Name,
                GroupEntityId     = department.Id,
                GroupEntityName   = department.Name,
                UserName          = user.Identity.Name
            };

            await _mediator.Publish(notification);

            return(Unit.Value);
        }