public async Task <int> Handle(InsertEmployeeCommand request, CancellationToken cancellationToken)
        {
            var vacationtypes = await VacationTypeRepository.Select();

            var vacationdays = new Dictionary <DonVo.CQRS.Standard21.Domain.Model.Company.VacationType, int>();

            foreach (var item in request.VacationDays)
            {
                vacationdays.Add(vacationtypes.Single(t => t.Id == item.Key), item.Value);
            }

            var position = await PositionRepository.Get(request.PositionId);

            if (position == null)
            {
                throw new ArgumentOutOfRangeException("Position does not exist.");
            }

            var department = await DepartmentRepository.Get(request.DepartmentId);

            if (department == null)
            {
                throw new ArgumentOutOfRangeException("Department does not exist.");
            }

            var manager = await EmployeeRepository.Get(request.ManagerId.GetValueOrDefault(0));

            var employee = new DonVo.CQRS.Standard21.Domain.Model.Company.Employee
                           (
                vacationdays,
                request.FirstName,
                request.LastName,
                request.BirthDate,
                request.Gender,
                request.Email,
                request.Phone,
                request.Street,
                request.PostalCode,
                request.City,
                position,
                department,
                manager
                           );

            var id = await EmployeeRepository.Insert(employee);

            var user = await UserManager.FindByIdAsync(employee.ApplicationUserId.ToString());

            await UserManager.AddToRolesAsync(user, request.Roles);

            await Mediator.Publish(new EmployeeInsertedEvent { Id = employee.Id });

            return(id);
        }
 public void LoadFromDomain(DonVo.CQRS.Standard21.Domain.Model.Company.Employee entity)
 {
     Id         = entity.Id;
     FirstName  = entity.FirstName;
     LastName   = entity.LastName;
     FullName   = entity.FullName;
     Gender     = entity.Gender ? "Male" : "Female";
     BirthDate  = entity.BirthDate;
     Email      = entity.Email;
     Phone      = entity.Phone;
     Position   = entity.Position.Name;
     Department = entity.Department.Name;
     ManagerId  = entity.ManagerId;
 }
        public void LoadFromDomain(DonVo.CQRS.Standard21.Domain.Model.Company.Employee entity, IEnumerable <DonVo.CQRS.Standard21.Domain.Model.Company.Holiday> holidays, int year)
        {
            Id         = entity.Id;
            FirstName  = entity.FirstName;
            LastName   = entity.LastName;
            FullName   = entity.FullName;
            Gender     = entity.Gender ? "Male" : "Female";
            BirthDate  = entity.BirthDate;
            Email      = entity.Email;
            Phone      = entity.Phone;
            Street     = entity.Street;
            PostalCode = entity.PostalCode;
            City       = entity.City;
            Position   = new PositionViewModel();
            Position.LoadFromDomain(entity.Position);
            Department = new DepartmentViewModel();
            Department.LoadFromDomain(entity.Department);
            Manager    = entity.Manager?.FullName;
            ManagerId  = entity.ManagerId;
            RowVersion = Convert.ToBase64String(entity.RowVersion);

            Vacations = new List <VacationViewModel>();
            foreach (var item in entity.GetVacations(year))
            {
                var vm = new VacationViewModel();
                vm.LoadFromDomain(item, holidays);
                Vacations.Add(vm);
            }

            Contracts = new List <ContractViewModel>();
            foreach (var item in entity.GetContracts())
            {
                var vm = new ContractViewModel();
                vm.LoadFromDomain(item);
                Contracts.Add(vm);
            }

            Statistics = new List <StatisticViewModel>();
            foreach (var item in entity.GetVacationStatistics(year, holidays))
            {
                var vm = new StatisticViewModel();
                vm.LoadFromDomain(item);
                Statistics.Add(vm);
            }
        }
        public void LoadFromDomain(DonVo.CQRS.Standard21.Domain.Model.Company.Employee entity)
        {
            if (entity == null)
            {
                return;
            }

            Id                    = entity.Id;
            FirstName             = entity.FirstName;
            LastName              = entity.LastName;
            FullName              = entity.FullName;
            Gender                = entity.Gender ? "Male" : "Female";
            BirthDate             = entity.BirthDate;
            Email                 = entity.Email;
            Phone                 = entity.Phone;
            Street                = entity.Street;
            PostalCode            = entity.PostalCode;
            City                  = entity.City;
            AvailableVacationDays = entity.CurrentVacationDays.ToDictionary(k => k.Key.Name, v => v.Value);
            PositionId            = entity.Position.Id;
            DepartmentId          = entity.Department.Id;
            ManagerId             = entity.Manager?.Id;
            RowVersion            = Convert.ToBase64String(entity.RowVersion);
        }