Beispiel #1
0
        public async Task <Role> CreateAsync(Role dto, Action <string, string> AddErrorMessage)
        {
            if (!await ValidateCrUpDataAsync(dto, AddErrorMessage))
            {
                return(null);
            }

            RoleEntity entity = _mappingService.DtoToEntity(dto);

            try
            {
                await _roleManager.CreateAsync(entity);
            }
            catch (Exception)
            {
                entity = null;
                AddErrorMessage?.Invoke("General", "Role with the same name already exists!");
            }
            return(_mappingService.EntityToDto(entity));
        }
        public override Position EntityToDto(PositionEntity entity)
        {
            Position dto = new Position
            {
                ID          = entity.ID,
                Description = entity.Description,
                Order       = entity.Order,
                Title       = entity.Title
            };

            List <Role> roleDtos = new List <Role>();

            foreach (RoleEntity r in entity.RoleEntity)
            {
                roleDtos.Add(_roleMappingService.EntityToDto(r));
            }

            dto.Role = roleDtos;

            return(dto);
        }